У меня есть база данных с информацией, когда я запрашиваю данные, я хочу, чтобы в моем ListView
отображался только один столбец, чтобы пользователь мог выбрать информацию, которую он хочет отобразить
Это мой помощник по базе данных:
public Cursor viewData () {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("Select * from " +TABLE_NAME, null);
return res;
}
И мой код:
private void viewData() {
Cursor cursor = db.viewData();
if (cursor.getCount()== 0){
Toast.makeText(this,"No Data To Show", Toast.LENGTH_LONG).show();
}else {
while(cursor.moveToNext()){
listItems.add(cursor.getString(0));//index 1 is name, 0 is ID
}
String[] StringArray = new String[]{
DatabaseHelper.COL_2
};
int[] IntArray = new int[]{
R.id.textView1
};
adapter = new SimpleCursorAdapter(this, R.layout.item_layout, cursor, StringArray, IntArray);
userList.setAdapter(adapter);
}
}
мой файл item_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mway">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textColor="@color/colorPrimary"
android:textSize="28sp"
android:textStyle="bold"/>
</RelativeLayout>