我希望我的listitem仍然響應onListItemClick()
,但另外我想要一個額外的圖像在一個原始的它有自己的點擊事件。經典的方式,爲圖像定義onClickListener
不工作。什麼I have found is that I have to define my own listadapter and override getView()
method。我鎖定了定義新的適配器類,我從來沒有使用過自定義適配器。我想通過標籤導航,onListItemClick()去標籤1和ImageClick去標籤2.它適用於onListItemClick()
但是當我在MySimpleAdapter.getView與NullPointerException異常添加第二個點擊事件的圖像應用程序崩潰()。任何幫助將不勝感激。謝謝。onListItemClick()+ ListView上的可點擊圖像
public class ListaActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
MySimpleAdapter adapter = new MySimpleAdapter(this, elem, R.layout.list_item,
new String[]{"name","number","address"}, new int[]{R.id.name,R.id.num,R.id.adr});
setListAdapter(adapter);
}
public class MySimpleAdapter extends SimpleAdapter{
Context context;
//Activity activity;
public MySimpleAdapter(Context context, ArrayList<HashMap<String, String>> elements,int layout, String [] from, int [] to){
super(context,el,layout,from,to);
this.context = context;
//this.activity = (Activity) context;
}
@Override
public View getView(int position,View convertView, ViewGroup parent){
View view = super.getView(position, convertView, parent);
ImageView image = (ImageView)findViewById(R.id.btn);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int tab=2;
MyTabActivity.switchToTab(tab);
}
});
return view;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id){
int tab = 1;
MyTabActivity.switchToTab(tab);
}
}
後堆棧跟蹤,也你在哪裏定義標籤? – user370305