小编Bru*_*ida的帖子

如何在Listview中实现onClick

我想这很简单.

我点击它时想要对行中的文本进行烘烤.这是我的代码:

公共类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();
}
Run Code Online (Sandbox Code Playgroud)

}

谢谢!

android onclick android-listview

0
推荐指数
1
解决办法
1017
查看次数

在listview onclick中从数据库获取Id

我有这个类,它从数据库中获取数据并显示在列表视图中.

有没有办法从数据库中获取Id并烘烤它?

现在吐司正在回归: android.database.sqlite.SQLiteCursor@4180c088

 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.openToRead();

     Cursor cursor = mySQLiteAdapter.queueAll();
     startManagingCursor(cursor);

     String[] from = new String[]{SQLiteAdapter.KEY_NOME,SQLiteAdapter.KEY_ID};
     int[] to = new int[]{R.id.text,R.id.id};

     SimpleCursorAdapter cursorAdapter =
      new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

     listContent.setAdapter(cursorAdapter);

     listContent.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView<?> parent, View view, int position,
                 long id) {
                //GET ID FROM DATABASE
                Toast.makeText(getBaseContext(), parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
                //THIS TOAST IS RETURNING …
Run Code Online (Sandbox Code Playgroud)

database android android-listview

0
推荐指数
1
解决办法
3212
查看次数

标签 统计

android ×2

android-listview ×2

database ×1

onclick ×1