in the mainActivity i have a listView
with a cutomised adapter, the adapter class extends BaseAdapter
.
in the mainActivity i am trying to show a message when an item is clikced, so i called OnItemClickListener
and inside it i show a toast
. but when i click an item the nothing is displayed.
please et me know what i am missing.
MainActivity:
private void setUpListView() {
// TODO Auto-generated method stub
this.topicsList = new ArrayList<String>();
for (int i = 0; i < this.topics.length; i++) {
this.topicsList.add(topics[i]);
}
this.adapter = new listViewAdapter(getApplicationContext(), this.topicsList);
this.listView.setAdapter(adapter);
this.listView.setOnItemClickListener(listViewitemListener);
}
....
....
private OnItemClickListener listViewitemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "item clicked", Toast.LENGTH_SHORT).show();
}
};
BaseAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater layoutinflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutinflater.inflate(R.layout.list_items_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvlist_topic);
CheckBox cb = (CheckBox) convertView.findViewById(R.id.cbList_hook);
ImageView iv = (ImageView) convertView.findViewById(R.id.ivList_delete);
tv.setText(this.arrayList.get(position));
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
return convertView;
}