我從我的數據庫中拉出一些數據,並讓它正確地填充TextView。我遇到的問題是當我點擊列表中的按鈕時,按鈕什麼也不做。我在onClick中添加了代碼完成,但該按鈕沒有響應。我查看了其他堆棧文章並嘗試瞭解決方案,但它們不起作用。我相信這是明顯的我缺少的東西。這裏是我的代碼listAdapter中的按鈕不工作
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:id="@+id/visitorNotLeft"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/companies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<Button
android:id="@+id/timeOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
android:layout_weight="1"
android:text="@string/timeOut" />
</TableRow>
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
timeOut = (Button)v.findViewById(R.id.timeOut);
timeOut.setTag(position);
timeOut.setFocusable(false);
timeOut.setFocusableInTouchMode(false);
timeOut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
這裏是我的適配器代碼
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
ListAdapter adapter = new SimpleAdapter(GetDataFromDB.this,
productsList, R.layout.list_of_visitors_not_signed_out,
new String[] { TAG_NAME, TAG_COMPANY }, new int[] {
R.id.names, R.id.companies });
// updating listview
setListAdapter(adapter);
}
如果你要我添加更多的代碼讓我知道。
您需要添加事件監聽到getview方法在適配器 –
你可以發佈您的適配器代碼? –
我剛加了我的適配器代碼 – Aaron