Ich versuche, ListView aus der Datenbank über SimpleCursorAdapter zu füllen, aber es gibt Fehler. verursacht durch: java.lang.IllegalArgumentException: Spalte '_id' existiert nichtAndroid SimpleCursorAdapter füllen ListView aus Datenbank
Hier ist meine BlistActivity, die meine ListView enthält.
public class BListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blist);
MyDBHandler myDBHandler = new MyDBHandler(this,null,3);
ListView listView = (ListView) findViewById(R.id.blistView);
Cursor cursor = myDBHandler.showAllRecords();
String[] columnNames = new String[]{"name_number"};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
columnNames,
new int[]{android.R.id.text1});
listView.setAdapter(adapter);
}
}
Hier ist mein XML-Code für diese Aktivität.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.haroon.vuultimateblocker.BListActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/blistView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:choiceMode="multipleChoice"/>
</RelativeLayout>
es auch erwähnenswert ist, dass ich das Listview als Multiple-Choice benötigen.