Android使用getSupportFragmentManager将类数据传递到ListVew

时间:2014-09-01 09:37:53

标签: android android-sqlite

webServerDataBase获取数据后,我想将数据传递给ListView getSupportFragmentManager。此方法从具有此结构的类中获取数据:

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)

屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

我正确的你正在尝试替换List而不是Fragment,getSupportFragmentManager()。beginTransaction()。replace expect一个占位符和一个你没有提供的片段对象

编辑: 你不能通过这种方式将数据结构传递给Fragment!您可以在替换后获取yourFragment对象,然后将数据作为参数传递给它或定义接口并实现callBack方法:

YouFragment frag = (YouFragment) SupportfragmentManager.findFragmentByTag("YourFragment");
frag.initList(ReceivedSmsList);