Android 台灣中文網
標題:
SimpleCursorAdapter要怎麼加入button click事件呢?
[打印本頁]
作者:
wind8894
時間:
2013-3-23 23:41
標題:
SimpleCursorAdapter要怎麼加入button click事件呢?
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
{
}
}
}
複製代碼
作者:
xjxuvup
時間:
2013-3-24 21:43
幫你找了一下資料
如果你不排斥簡中
那這篇簡中文章,應該是沒問題,看起來淺顯易懂
你參考看看唄
http://blog.csdn.net/kechanghe0705/article/details/6638200
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1