单击连接到数据库的列表视图时尝试获取名称。 搜索了解决方案,但找不到这样的解决方案。试图自己解决很长时间但没有做到。我的代码:
public void v() {
Cursor cursor = myDBHandler.getDatabaseCursor();
final String []arr = new String[]{myDBHandler.getColumnName()};
int idView[]=new int[]{R.id.lv_tv2};
SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.lvlayout,
cursor, arr, idView);
ListView lv=(ListView)findViewById(R.id.ap_Lv1);
lv.setAdapter(simpleCursorAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor1 = myDBHandler.getDatabaseCursor();
String s = cursor1.getString(cursor1.getColumnIndex(myDBHandler.getColumnName()));
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
cursor1.close();
}
});
}
MyDBHandler类中的getColumnName()方法是:
public String getColumnName(){
return COLUMN_NAME;
}
答案 0 :(得分:1)
mCursor.moveToPosition(position);
String s = mCursor.getString(mCursor.getColumnIndex(myDBHandler.getColumnName()));
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();