我想检索Listview中某一个项目的ID。现在只能获得位置。如何检索Listview中某一个位置的ID?
public class OSListActivity extends ListActivity {
................
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
................
................
MatrixCursor cursor;
cursor = datasource.getnameList();
if (cursor.moveToFirst()) {
startManagingCursor(cursor);
String vdstatus = cursor.getString(6);
System.out.println("vdstatus : " + vdstatus);
String[] from = { "name", "desc", "status", "path", "folder",
BaseColumns._ID };
int[] to = { R.id.name, R.id.desc, R.id.status, R.id.path };
final VSsimplecursoradapter adapter = new VSsimplecursoradapter(
this, R.layout.row, cursor, from, to);
setListAdapter(adapter);
}
}
@Override
public void onListItemClick(ListView parent, View view, int position,
long id) {
Intent intent = new Intent(this, VSDetailsActivity.class);
intent.putExtra("com.manager.boot.r1223."+BaseColumns._ID, position);//TODO put _id instead of position
startActivity(intent);
}
}
Edit: 解决
public void onListItemClick(ListView parent, View view, int position,
long id) {
// Starts TestDetails activity on clicking a list item.
Cursor cursor = (Cursor) adapter.getItem(position);
Intent intent = new Intent(this, VSDetailsActivity.class);
intent.putExtra("com.manager.boot.r1223."+BaseColumns._ID, cursor.getInt(cursor
.getColumnIndex("_id")));
startActivity(intent);
}