Reputation: 312
I'm having a hard time figuring out why my onClick is getting caught in the wrong class.
I have a ListView
with a custom adapter and inflating a custom row.
In my row.xml I have put onRowClick in the onClick method and in the code behind I have:
public void onRowClick(View v)
{
//do something;
}
The flow of the app is: Login => Show ListView
I call finish()
in Login if successful and then call intent to open the class with the ListView.
My problem is that the onClick gets caught in the Login class and not in the ListView class.
Code:
public class TabComeLeave extends Activity
{
private ProgressDialog m_ProgressDialog = null;
private ArrayList<Item> m_items = null;
private ItemAdapter m_adapter;
private Runnable viewItem;
private ListView listViewItem;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_come_leave);
listViewItems = (ListView)findViewById(R.id.listViewItems);
listViewItems .setClickable(true);
fillItemList();
}
public void fillItemList()
{
m_adapter = new ItemAdapter(SystemUtil.getInstance(), R.layout.list_row_come_leave, m_Items);
listViewItems.setAdapter(m_adapter);
}
ItemAdapter.java:
public class ItemAdapter extends ArrayAdapter<Item>
{
private ArrayList<Item> items;
public ItemAdapter(Context context, int textViewResourceId, ArrayList<Item> items)
{
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)SystemUtil.getInstance().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row_come_leave, null);
}
Item item = items.get(position);
if (item!= null)
{
TextView itemName = (TextView)v.findViewById(R.id.textViewItemName);
if (itemName != null)
{
itemName .setText(item.getitemFirstName());
}
}
return v;
}
}
Can someone point me in the right direction?
Thanks a lot.
Upvotes: 2
Views: 180
Reputation: 6141
Why don't you use onItemClickListener
instead of onRowClick
when using a ListView, this problem would have no chance to occure then.
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//do something
}
});
Upvotes: 2