0

我想这很简单。

当我点击它时,我想烤面包行中的文本。这是我的代码:

公共类 AndroidSQLite 扩展 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();
}

}

谢谢你!

4

5 回答 5

5

写下来

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

            }
        });
于 2012-10-29T13:40:28.803 回答
3

您可以使用

listContent.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {

            }

        });
于 2012-10-29T13:37:46.607 回答
1

像这样:

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

            String item = ...;

            Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();

        }
    });
于 2012-10-29T13:38:02.360 回答
1

试试这个代码的项目点击

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

        String text = <Get Your from database is here in this string>;

        Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG).show();

    }
});
于 2012-10-30T05:12:38.873 回答
0

使用 onitemclick evetn 而不是 onclick。

listview.setOnItemClickListener(...);

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)

arg2 是列表中的索引。

于 2012-10-29T13:39:49.513 回答