馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
SimpleCursorAdapter要怎麼加入button click事件呢?
我現在listview已經有 ImageView、TextView、Button三個元件了
只有button這個我不知道要怎麼做出click事件,想請教大大解惑- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.page_g);
- listview = (ListView)findViewById(R.id.listview);
- dbhelper = new Mydbhelper(this);
- dbrw = dbhelper.getWritableDatabase();
- dbrw= (new Mydbhelper (getApplicationContext())).getWritableDatabase();
- cursor =dbrw.rawQuery("SELECT name,pic,_id from title",null);
-
- adapter = new SimpleCursorAdapter(this,R.layout.list_row,cursor,new String[]{"name","pic"},
- new int[]{R.id.food_name, R.id.food_pic});
- listview.setAdapter(adapter);
- listview.setOnItemClickListener(new ItemClickListener());
- }
- private final class ItemClickListener implements OnItemClickListener
- {
- public void onItemClick(AdapterView<?> parent, View view, int position, long id)
- {
- ListView lView = (ListView)parent;
- Cursor cursor = (Cursor) lView.getItemAtPosition(position);
- choose_name = cursor.getString(cursor.getColumnIndex("name"));
- if(choose_name.equals("aaa"))
- {
- Intent intent= new Intent(page_g.this,aaa .class);
- startActivity(intent);
- }
- else if(choose_name.equals("bbb"))
- {
- Intent intent= new Intent(page_g.this,bbb .class);
- startActivity(intent);
- }
- else
- {
- }
- }
- }
複製代碼 |
|