bluetooth99
2012-10-30 03:11
采纳率: 68.6%
浏览 5.1k

怎么在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 2012-10-30 06: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));
    
            }
        });
    
    点赞 打赏 评论
  • qq_27578023 2016-05-26 13:48

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

        }
    });的监听事件就行了
    
    点赞 打赏 评论

相关推荐 更多相似问题