Android Setting sqlite database values in an listview

后端 未结 1 1298
一整个雨季
一整个雨季 2020-12-12 07:03

I am Facing a problem in setting a ListView in android . Everything works ok but it is not setting the way i want it to set . here are the images whats happening

相关标签:
1条回答
  • 2020-12-12 07:14

    You are using multiple adapters in your list view.

    listview.setAdapter(new MyNotiAdapter(noticall.this, adi,adi1,adi2,adi3));
    

    And later

    listview.setAdapter(cursorAdapter);
    

    While, yes, the code runs, you are seeing some unexpected results.

    For example, that second image looks like you are displaying an Arraylist in one row instead of an element per row.

    And that is probably caused by this line where you toString some arraylists

    mySQLiteAdapter.insert(myrows.toString(),time1.toString(),name1.toString(),number1.toString());
    

    So, my suggestion is use one adapter (probably just a CursorAdapter since you are using SQLite) to display your data. And you can setAdapter only once inside onCreate and never need to set it again. You only reload the cursor.

    Another thing to note. Don't iterate on the cursor after you add it to an adapter. Because the adapter reads the cursor and displays its contents, then you are later exhausting the iterator.

    Cursor cursor = mySQLiteAdapter.getAllData();
    startManagingCursor(cursor);
    // ...
    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(noticall.this, R.layout.row2, cursor, from, to);
    
    while (cursor.moveToNext()){ // <--- This is bad
    
    0 讨论(0)
提交回复
热议问题