I have a gridview with items consisting of different views, among which an ImageButton which may or may not be present (depending on the case). I implemented onItemClick for each item inside the grid, but I also need to have a toast showing up when the info button is present (and pressed). Everything worked fine, except the fact that the items which contain the info button will not respond to onItemClick anymore, they only respond to the info icon being pressed. How can I make those items respond accordingly both to click on the info button and on other areas?
Here is the code for onItemClick():
@Override
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
getDayStatus((Date) _monthVectorList.get(0).get(arg2));
_listenerDateSelect.onDispatchDateSelect((Date) _monthVectorList.get(0).get(arg2));
}
and here is the imageButton for Info:
<ImageButton
android:layout_width="15dp"
android:layout_height="15dp"
android:id="@+id/tv_day_info"
android:layout_gravity="center"
android:gravity="right|center"
android:layout_marginLeft="1dp"
android:onClick="infoToast"
android:focusable="false"
/>
Also, here is the code for info toast:
public void infoToast(View view){
Date date = (Date) view.getTag();
List<String> dayDescription = getDayStatus(date);
Context context = (Context) getApplicationContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text = (String) dayDescription.get(2);
Toast.makeText(context, text, duration).show();
}
I tried setting the focus off to the imageButton, but it still does not work. I attach an image to get a better depiction of the issue: http://oi42.tinypic.com/2rcxrv6.jpg
try with:
inside imagebutton
add this to root layout of ImageButton
That because your "info Button" has gained focus form your gridview item, you can only click on the button, in this case is 'info Button'. However, you could also click on your gridview item by set the "info Button" NOT focusable. Try this:
Hope this helps.