Closed dongjinahn closed 9 years ago
I didn't catch it, do you mean disabling focus from the Fancybutton ?
Can you paste the code you've used so i can reproduce the same issue ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:descendantFocusability="blocksDescendants"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<mehdi.sakout.fancybuttons.FancyButton
android:id="@+id/fancy_button"
fancy:fb_textColor="#000000"
fancy:fb_iconPosition="top"
fancy:fb_defaultColor="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_gravity="center"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
code above is view_icon_btn.xml
public class GridAdapter extends BaseAdapter {
private static final String TAG = GridAdapter.class.getSimpleName();
private Context mContext;
private List<GridItem> mList;
public GridAdapter(Context c, List<GridItem> l) {
mContext = c;
mList = l;
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int position) {
return mList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(TAG, "getView(), position: " + position);
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.view_icon_btn, parent, false);
}
FancyButton fbtn = ViewHolder.get(convertView, R.id.fancy_button);
GridItem item = mList.get(position);
fbtn.setText..
..
return convertView;
}
}
and this is Adapter of my grid view
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick(), position: " + position);
MainActivity2 mainActivity2 = (MainActivity2) getActivity();
switch (position) {
case 0:
mainActivity2.switchFragment(DefinitionFragment.newInstance("Section A"));
break;
case 1:
mainActivity2.switchFragment(DailyFragment.newInstance("Section B"));
break;
case 2:
mainActivity2.switchFragment(StatMainFragment.newInstance("Section C"));
break;
case 3:
mainActivity2.switchFragment(LibBookmarkFragment.newInstance("Section D"));
break;
}
}
});
and this is onItemClick Listener.. (but as i mentioned, not called and fancy button.onclick() was called instead.
Have you tried to disable the focus programmatically by doing fbtn.setFocusable(false)
?
Make sure you add it as last instruction on your getView()
Any updates ?
Same problem, and solved after setFocusable programmatically. Thanks medyo!
i tried to use this fancy~ fancyButton in my GridView
but as i expected, it didn't work because it gets focus more than GridView
so i assigned some attrs to fancyButton like
it worked great when it was ImageButton,
But.. it didn't work.. so i can't not use onItemClickListener of GrideView right now T^T