Android 台灣中文網

標題: SimpleCursorAdapter要怎麼加入button click事件呢? [打印本頁]

作者: wind8894    時間: 2013-3-23 23:41
標題: SimpleCursorAdapter要怎麼加入button click事件呢?
SimpleCursorAdapter要怎麼加入button click事件呢?

我現在listview已經有 ImageView、TextView、Button三個元件了

只有button這個我不知道要怎麼做出click事件,想請教大大解惑
  1. public void onCreate(Bundle savedInstanceState) {
  2.         super.onCreate(savedInstanceState);
  3.         setContentView(R.layout.page_g);
  4.         listview = (ListView)findViewById(R.id.listview);  
  5.         dbhelper = new Mydbhelper(this);
  6.                 dbrw = dbhelper.getWritableDatabase();
  7.                 dbrw= (new Mydbhelper (getApplicationContext())).getWritableDatabase();   
  8.         cursor =dbrw.rawQuery("SELECT name,pic,_id from title",null);
  9.         
  10.         adapter = new SimpleCursorAdapter(this,R.layout.list_row,cursor,new String[]{"name","pic"},
  11.                         new int[]{R.id.food_name, R.id.food_pic});
  12.         listview.setAdapter(adapter);
  13.         listview.setOnItemClickListener(new ItemClickListener());        
  14.     }              
  15.           private final class ItemClickListener implements OnItemClickListener
  16.           {
  17.                   public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  18.                   {
  19.                           ListView lView = (ListView)parent;
  20.             Cursor cursor = (Cursor) lView.getItemAtPosition(position);
  21.             choose_name = cursor.getString(cursor.getColumnIndex("name"));            
  22.             if(choose_name.equals("aaa"))
  23.                     {
  24.                     Intent intent= new Intent(page_g.this,aaa .class);                      
  25.                     startActivity(intent);
  26.                     }
  27.                     else if(choose_name.equals("bbb"))
  28.             {
  29.                             Intent intent= new Intent(page_g.this,bbb .class);                      
  30.                     startActivity(intent);
  31.             }
  32.                     else
  33.                     {                                    
  34.                     }            
  35.         }
  36.           }
複製代碼

作者: xjxuvup    時間: 2013-3-24 21:43
幫你找了一下資料
如果你不排斥簡中
那這篇簡中文章,應該是沒問題,看起來淺顯易懂
你參考看看唄
http://blog.csdn.net/kechanghe0705/article/details/6638200




歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1