android-viewflow
android-viewflow copied to clipboard
java.lang.IllegalArgumentException
Hi,
I use ViewFlow to make an alternative launcher and I got a problem. Every View of my ViewFlow contains a GridView with some icon. It work well but when I do a finish(); in an other activity in order to return to my activity with ViewFlow i got an error.
java.lang.IllegalArgumentException: parameter must be a descendant of this view at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4153) at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4090) at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:2129) at android.view.ViewRootImpl.draw(ViewRootImpl.java:1849) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1641) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2449) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method)
This error not happen when I use the Back Button on the Action Bar. I try to solve this problem since few weeks. One of the reason I found is when I use an activity with Theme i got this error again but there is an other reason and i don't find it.
private class ImageAdapter extends ArrayAdapter<View>{
Context context;
public ImageAdapter(Context context, ArrayList<View> grid){
super(context,0,grid);
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
final LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.gridview_background, parent, false);
}
ArrayList<ApplicationInfo> listApps = new ArrayList<ApplicationInfo>();
int start=position *GRID_APPLICATIONS_NUMBER;
int end=start+GRID_APPLICATIONS_NUMBER;
for(int i = start; (i< end) && (i<mApplications.size()) ;i++){
listApps.add(mApplications.get(i));
}
GridView mGrid = (GridView) convertView.findViewById(R.id.all_apps);
mGrid.setAdapter(new HomeFlow.ApplicationsAdapter(context, listApps));
bindButtons(mGrid);
mGrid.setSelection(0);
return convertView;
}
}
This is my implementation of the adapter in order to stack the viewflow.
private void bindApplications() {
ArrayList<View> alView = new ArrayList<View>();
int div = mApplications.size()/GRID_APPLICATIONS_NUMBER;
if(mApplications.size()%GRID_APPLICATIONS_NUMBER != 0){
div++;
}
for(int i = 0; i<div;i++){
alView.add(new View(this));
}
ViewFlow viewflow = (ViewFlow) findViewById(R.id.viewflow);
viewflow.setAdapter(new ImageAdapter(this, alView));
CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
viewflow.setFlowIndicator(indic);
}
And here my initialization of the view.
If someone can help me ! Thanks.
I solve the problem ! The problem was that i call bindApplications in my onResume so when I return to this activity I stack again my ViewFlow and i got this error !
Hello... I am facing same problem on some devices. I am calling notifyDataSetChanged() in onResume of class in which i am setting adapter for ViewFlow. I don't get any such exception if i don't call notifyDataSetChanges(). Moreover this exception is shown only in some devices. Is there any other solution to this problem? I need to get my grid views refreshed on pressing back and resuming this activity.
I didn't work with this library anymore, I found that you can easily do the same things with Fragment on Android. So I don't know. Good luck.