綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] SimpleCursorAdapter要怎麼加入button click事件呢?

[複製連結] 查看: 2315|回覆: 1|好評: 0
跳轉到指定樓層
樓主
wind8894 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-3-23 23:41

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
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.           }
複製代碼
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
xjxuvup | 收聽TA | 只看該作者
發表於 2013-3-24 21:43
幫你找了一下資料
如果你不排斥簡中
那這篇簡中文章,應該是沒問題,看起來淺顯易懂
你參考看看唄
http://blog.csdn.net/kechanghe0705/article/details/6638200
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則