2 bluetooth99 bluetooth99 于 2012.10.30 11:11 提问

怎么在Listview中实现onClick?

我猜我的问题很简单

我要实现的功能代码如下:

public class AndroidSQLite extends Activity { private SQLiteAdapter mySQLiteAdapter;

@Override
public 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();
}
}

请帮忙。谢谢

2个回答

ce_la_vie
ce_la_vie   2012.10.30 14:03
已采纳

试试:

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));

        }
    });
aa77777
aa77777 log。e方法屡试不爽
3 年多之前 回复
qq_27578023
qq_27578023   2016.05.26 21:48

listContent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View arg1,
int position, long id) {

    }
});的监听事件就行了
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!