亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 ViewPager 以防止應用出錯和崩潰?

如何修復 ViewPager 以防止應用出錯和崩潰?

慕婉清6462132 2021-08-19 16:42:43
我正在登錄頁面上工作,基于 Androidhive 教程,問題Viewpager在 2 個布局下工作正常,但對于3 個布局應用程序會崩潰。在 androidhive 教程中使用了 2 個布局,但我想使用 3 個,因為我收到 sms 然后 otp 然后注冊,所以問題在于第 3 個布局,它不會出現和崩潰。以下是代碼:XML    <LinearLayout        android:id="@+id/layout_phone_registration"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:background="@color/colorPrimary"        android:gravity="center_horizontal"        android:orientation="vertical">        <ImageView            android:layout_width="60dp"            android:layout_height="60dp"            android:layout_gravity="center_horizontal"            android:layout_marginBottom="25dp"            android:layout_marginTop="100dp"            android:src="@mipmap/ic_launcher" />        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_marginBottom="25dp"            android:gravity="center_horizontal"            android:inputType="textCapWords"            android:paddingLeft="40dp"            android:paddingRight="40dp"            android:text="@string/msg_enter_mobile"            android:textColor="@android:color/white"            android:textSize="14dp" />        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="vertical">            <EditText                android:id="@+id/inputMobile"                android:layout_width="240dp"                android:layout_height="wrap_content"                android:background="@android:color/white"                android:fontFamily="sans-serif-light"                android:hint="@string/lbl_mobile"                android:inputType="phone"                android:maxLength="12"                android:padding="5dp"                android:textColor="@color/colorPrimary"                android:textCursorDrawable="@null"                android:textSize="18dp" />
查看完整描述

2 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

根據你的錯誤


java.lang.UnsupportedOperationException:必需的方法 destroyItem 未被覆蓋


您需要在尋呼機適配器中添加此方法


@Override

void destroyItem (ViewGroup container, int position, Object object){

    ((ViewPager) container).removeView((View) object);

    // more code if needed

}


查看完整回答
反對 回復 2021-08-19
?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

覆蓋destroyItem在你的方法ViewPagerAdapter類和刪除OBJ中container.removeView(obj as LinearLayout),其中LinearLayout是你的根布局


@Override 

void destroyItem(ViewGroup container, int position, Object obj) {

            container.removeView(obj as LinearLayout)

        }


查看完整回答
反對 回復 2021-08-19
  • 2 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號