Hi ,
Thanks again for timely responses. I have already made my imageViews non-focusable . This is the code snippet :
Using java Syntax Highlighting
imageView.setEnabled(false);
imageView.setFocusable(false);
imageView.setFocusableInTouchMode(false);
imageView.setClickable(false);
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
When the GridView gains focus, it always tries to give focus to the first of its child views. I have used this code-snippet :
Using java Syntax Highlighting
gridView.setFocusable(true);
gridView.setFocusableInTouchMode(true);
gridView .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
Parsed in 0.030 seconds, using
GeSHi 1.0.8.4
Regardless of this , if the first child is a space-filler and it always gains focus. So to overcome this , I use a method getFirstFocusableView() in my Adapter class to retrieve the first focusable view and give it the focus.
But on orientation-change , getView() method in Adapter class is called to render each child view of the GridView ( just like how a GridView is rendered for the first time when setAdapter() is invoked ) . Even if I try to give focus to the first focusable view by calling the corresponding method as the last statement in onConfigurationChanged(), that doesn't work. This is because getView() in Adapter class is invoked by GridView internally to render its child views at indeterminate times. This is my Adapter class :
Using java Syntax Highlighting
public class MyAdapter extends BaseAdapter {
private List<View> views;
public MyAdapter(List<View> views) {
super();
// TODO Auto-generated constructor stub
this.views = new ArrayList<View>(views);
}
public int getCount() {
// TODO Auto-generated method stub
return views.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return views.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return views.get(position);
}
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
if (views.get(position) instanceof ImageButton) {
return true;
}
return false;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 2;
}
public List<View> getViews() {
return views;
}
public View getFirstFocusableView() {
// TODO Auto-generated method stub
for (View v : views) {
if (v.isEnabled() && v.isFocusable() && v.isClickable()
&& v instanceof ImageButton) {
return v;
}
}
return null;
}
}
Parsed in 0.040 seconds, using
GeSHi 1.0.8.4
Can u give me some internals on how GridView uses setAdapter() to render its child views or is there any other method to solve my problem ?
Thanks
Satish