I have a ListView, with items with this layout:
<LinearLayout ...>
<LinearLayout ...>
<!--Elements -->
</LinearLayout>
<LinearLayout ...>
<!--Elements -->
</LinearLayout>
</LinearLayout>
So my items have two different sections. I want to be able to setup different onclickListener inside each item(one for each LinearLayout). I have tried so far to override the onListItemClick, but it doesnt seem to work properly:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ViewGroup vg = (ViewGroup)v;
vg.getChildAt(0).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mCtx, "element1", Toast.LENGTH_SHORT).show();
}
});
vg.getChildAt(1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mCtx, "element2", Toast.LENGTH_SHORT).show();
}
});
}
Any ideas how to tackle the problem?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…