从webServer或DataBase获取数据后,我想用getSupportFragmentManager将数据传递给ListView。此方法从具有以下结构的类中获取数据:
public class ReceiveFields {
public long lastId;
public String
public String
public String
public String
public String
private Context
public
}
}从数据库中传递和获取数据:
ListSMS = db.getAllReceivedSMSFromDatabase();getAllReceivedSMSFromDatabase函数:
public List<ReceiveFields> getAllReceivedSMSFromDatabase() {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + this.RECEIVE_FIELDS_TABLE ;
Cursor cursor = db.rawQuery(selectQuery, null);
List<ReceiveFields> ListSMS = new ArrayList<ReceiveFields>();
cursor.moveToFirst();
while (cursor.moveToNext()) {
ListSMS.add(new ReceiveFields(
Long.valueOf(cursor.getString(cursor.getColumnIndex("lastId"))),
cursor.getString(cursor.getColumnIndex("smsNumber")),
cursor.getString(cursor.getColumnIndex("mobileNumber")),
cursor.getString(cursor.getColumnIndex("senderName")),
cursor.getString(cursor.getColumnIndex("smsBody")),
cursor.getString(cursor.getColumnIndex("receiveDate"))));
}
cursor.close();
db.close();
return ListSMS;
}getAllReceivedSMSFromDatabase函数没有任何问题,可以以List<ReceiveFields>格式返回数据
创建数据并将其传递到ListView
List<ReceiveFields> receivedSMSList = db.getAllReceivedSMSFromDatabase();
getSupportFragmentManager().beginTransaction().replace(R.id.drawer, ListSMS).commit();我现在得到了一个错误:
Error:(288, 63) java: no suitable method found for replace(int,java.util.List<ir.tsms.wsdl.ReceiveFields>)
method android.support.v4.app.FragmentTransaction.replace(int,android.support.v4.app.Fragment,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
method android.support.v4.app.FragmentTransaction.replace(int,android.support.v4.app.Fragment) is not applicable
(actual argument java.util.List<ir.tsms.wsdl.ReceiveFields> cannot be converted to android.support.v4.app.Fragment by method invocation conversion)屏幕截图:

发布于 2014-09-01 17:55:17
因为我没弄错,你正在尝试替换一个List而不是Fragment,getSupportFragmentManager().beginTransaction().replace期望一个占位符和一个你没有提供的片段对象。
编辑:您不能通过replace以这种方式将数据结构传递给片段!您可以在替换yourFragment对象后获取它,然后将数据作为参数传递给它,或者定义一个接口并实现callBack方法:
YouFragment frag = (YouFragment) SupportfragmentManager.findFragmentByTag("YourFragment");
frag.initList(ReceivedSmsList);https://stackoverflow.com/questions/25602899
复制相似问题