Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android将片段参数而不是列表传递到ListView_Java_Android_Listview_Android Sqlite - Fatal编程技术网

Java Android将片段参数而不是列表传递到ListView

Java Android将片段参数而不是列表传递到ListView,java,android,listview,android-sqlite,Java,Android,Listview,Android Sqlite,我可以从Web服务器获取数据,并使用以下类将其正确传递到ListView: ReceiveFields类结构: public class ReceiveFields { public long lastId; public String smsNumber; public String mobileNumber; public String senderName; public String smsBody; public String recei

我可以从Web服务器获取数据,并使用以下类将其正确传递到ListView:

ReceiveFields
类结构:

public class ReceiveFields {
    public long lastId;
    public String smsNumber;
    public String mobileNumber;
    public String senderName;
    public String smsBody;
    public String receiveDate;
    private Context ctx;
}
ReceivedSMS
类从Web服务获取数据:

public class ReceivedSMS extends ListFragment implements AbsListView.OnScrollListener {
    private List<ReceiveFields> rows;
    private int prevVisibleItem;
    private TSMS tsms;
    private String username;
    private String password;
    public  Long getLastReceivedSMSID;
    private boolean isFirstTime;
    private Context context;

    public ResivedSMS(Context context, String username, String password) {
        this.username = username;
        this.password = password;
        this.context = context;
    }

    public ResivedSMS(String username, String password, long start, long count,Context context) {
        this.username = username;
        this.password = password;
        this.context = context;
        tsms = new TSMS(context ,new User(username, password));
        getResivedSMS(start , count);
    }

    public ResivedSMS(List<ReceiveFields> receivedSMSList,Context context){
        rows = receivedSMSList;
        this.context = context;
    }

    public List<ReceiveFields> getResivedSMS(long start, long count) {
        tsms = new TSMS(context,new User(this.username, this.password));
        try {
            rows = tsms.getReceivedSMS(start, count);
        }
        catch (TException e) {
            e.printStackTrace();
            Log.e("ERROR IN Fetch SMS From WebService List<ReceiveFields> getResivedSMS(long start, long count) " , String.valueOf(e));
        }
        return rows;
    }
并传递到ListView:

getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();
所有这些都是正确的,我没有问题。但我想从数据库中获取数据并将其传递,而不是接收数据,如下所示:

List<ReceiveFields> r1 = db.getAllReceivedSMSFromDatabase();

receivedSMSList = new ResivedSMS(r1,context);

getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();
注意:我的数据库不是空的,有20行

getAllReceivedSMSFromDatabase
返回值与
GetResizedSMS
类似,但我得到以下错误:

getAllReceivedSMSFromDatabase
带有'LogCat:

ID: 19  lastId: 29901991  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/8/3

ID: 19  lastId: 29901992  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/9/3

ID: 19  lastId: 29901993  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/10/3

问题是您正在将一个列表作为参数传递给,而它需要一个片段作为参数

公共抽象片段事务替换(int-containerwid,片段片段

您已将列表作为参数传递,而不是传递片段


尝试传递ReceivedSMS(它
扩展了ListFragment
)而不是ListSMS,后者是一个列表(
列表ListSMS

设置列表对象,当它需要片段时,在这里初始化并设置片段类ReceivedSMS。@jitainsharma我做不到。如何?Like ReceivedSMS ReceivedSMS=新的ReceivedSMS(上下文、用户名、密码);我不相信我,先生。你能用正确的方式粘贴帖子吗TuxWorld 21分钟ago@TuxWorld重复这么多次并不是获得帮助的最佳途径。。。此外,您的时间戳已经在您的消息中,但您也复制了它。
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;
}
ID: 19  lastId: 29901991  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/8/3

ID: 19  lastId: 29901992  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/9/3

ID: 19  lastId: 29901993  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/10/3