誰がどのように、なぜこれが起こるのか知っていますか?
java.lang.ClassCastException: android.support.v4.view.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.ListView.clearRecycledState(ListView.java:519)
at android.widget.ListView.resetList(ListView.java:506)
at android.widget.ListView.layoutChildren(ListView.java:1540)
at android.widget.AbsListView.onLayout(AbsListView.java:2296)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1141)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14055)
at android.view.ViewGroup.layout(ViewGroup.java:4604)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1992)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1813)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
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:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
私がしたことは
ビュー ページャーでシャーロック フラグメント アクティビティを開く
ビューページャー内のリストビューの項目をクリックすると、2 番目のアクティビティに移動します
戻るボタンを押すと、viewpager を含むアクティビティに戻ります。
その3ステップの最初のアクションは問題ありませんが、2番目のステップと3番目のステップを数回速く繰り返すと、いつかその問題が発生します。
それを修正する方法はありますか?
これは私のコードです:
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.viewpagerindicator.PageIndicator;
import com.viewpagerindicator.TitlePageIndicator;
import ex.godofsmith.helper.LocationService;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
public class RestoFragmentActivity extends SherlockFragmentActivity {
private Intent locationService;
private ViewPager _mViewPager;
private RestoVPAdapter _adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resto);
setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
//set location service
locationService = new Intent(this, LocationService.class);
//end location service
setUpView();
}
@Override
public void onPause(){
super.onPause();
stopService(locationService);
}
@Override
public void onResume(){
super.onResume();
startService(locationService);
}
@Override
public void onDestroy(){
super.onDestroy();
//stopService(locationService);
}
private void setUpView(){
_adapter = new RestoVPAdapter(getApplicationContext(),getSupportFragmentManager());
_mViewPager = (ViewPager) findViewById(R.id.viewPager);
_mViewPager.setAdapter(_adapter);
_mViewPager.setCurrentItem(0);
_mViewPager.setOffscreenPageLimit(3);
PageIndicator mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(_mViewPager);
}
}
//==================
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class RestoVPAdapter extends FragmentStatePagerAdapter {
//protected static final String[] CONTENT = new String[] { "Recommended", "Best", "Nearby", "Promo", "New"};
protected static final String[] CONTENT = new String[] { "Nearby", "Promo", "New"};
private Context _context;
private int mCount = CONTENT.length;
public RestoVPAdapter(Context context, FragmentManager fm) {
super(fm);
_context=context;
}
@Override
public Fragment getItem(int position) {
Fragment f = new Fragment();
switch(position){
// case 0:
// //f=RestoRecommendedActivity.newInstance(_context);
// break;
// case 1:
// //f=RestoBestActivity.newInstance(_context);
// break;
case 0:
f=RestoNearByActivity.newInstance(_context);
break;
case 1:
f=RestoPromoFragment.newInstance(_context);
break;
case 2:
f=RestoNewActivity.newInstance(_context);
break;
}
return f;
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
return RestoVPAdapter.CONTENT[position % CONTENT.length];
}
}
//========= ビュー ページャーを含むアクティビティのレイアウト
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF000000"
app:footerColor="@color/greenslideup"
app:footerLineHeight="1dp"
app:footerIndicatorHeight="3dp"
app:footerIndicatorStyle="underline"
app:selectedColor="#FF000000"
app:selectedBold="true"/>
<ex.godofsmith.helper.CustomViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewPager" />
</LinearLayout>
/==== ビュー ページャーでのフラグメントのレイアウト ===
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/lvNearBy"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>