【发布时间】:2016-08-25 23:30:27
【问题描述】:
我知道这可能被称为重复问题,但我确信我的情况非常独特。基本上我需要一种方法来获取我的光标 id,即从数据库中为我的表解析到自定义适配器的 id。因此,当我单击该列表时,它会显示正确的 ID。这是我到目前为止所得到的......
请注意,我想使用 customadapter 而不是 cursoradapter。
//Get Categories from database
final Cursor cursor = dbHandler.getCategories(0);
if (cursor != null) {
if(cursor.moveToFirst()){
do{
Categories categories = new Categories();
categories.set_id(cursor.getInt(0));
categories.set_categoryname(cursor.getString(2));
categories.set_categoriescaption(cursor.getString(3));
//list.add(cursor.getString(cursor.getColumnIndex(dbHandler.COLUMN_CATEGORY_NAME)));
categoriesList.add(categories);
}while (cursor.moveToNext());
}
cursor.close();
}
光标从我的sqlite数据库中获取数据
listView = (ListView) view.findViewById(R.id.categories);
adapter = new CategoryAdapter(view.getContext(), R.layout.cursor_row, categoriesList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String cid = String.valueOf(id);
Toast.makeText(view.getContext(), cid , Toast.LENGTH_SHORT).show();
我希望在单击按钮时显示表格的真实 ID,而不是职位 ID。真实ID应该从1开始,但我在这里得到0。帮助将不胜感激。谢谢
【问题讨论】:
标签: java android sqlite android-sqlite custom-adapter