问题描述
- 怎么在Listview中实现onClick?
- 我猜我的问题很简单
我要实现的功能代码如下:
public class AndroidSQLite extends Activity { private SQLiteAdapter mySQLiteAdapter;@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listContent = (ListView)findViewById(R.id.contentlist); mySQLiteAdapter = new SQLiteAdapter(this); mySQLiteAdapter = new SQLiteAdapter(this); mySQLiteAdapter.openToRead(); Cursor cursor = mySQLiteAdapter.queueAll(); startManagingCursor(cursor); String[] from = new String[]{SQLiteAdapter.KEY_NOME}; int[] to = new int[]{R.id.text}; SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this R.layout.row cursor from to); listContent.setAdapter(cursorAdapter); mySQLiteAdapter.close();}}
请帮忙。谢谢
解决方案
试试:
listContent.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter View arg1 int position long id) { Log.i(""get ItemIDPosition""" + adapter.getItemIdAtPosition(position)); Log.i(""get ItemATPosition""" + adapter.getItemAtPosition(position)); } });
解决方案二:
listContent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter View arg1
int position long id) {
}});的监听事件就行了
时间: 2024-12-04 04:50:49