Fragment inflate上的IndexOutOfBoundsException

时间:2016-11-03 03:42:42

标签: android android-fragments

昨天我收到了这个错误

    java.lang.IndexOutOfBoundsException
      at android.graphics.Paint.getRunAdvance(Paint.java:2346)
      at android.text.TextLine.handleText(TextLine.java:748)
      at android.text.TextLine.handleRun(TextLine.java:898)
      at android.text.TextLine.measureRun(TextLine.java:417)
      at android.text.TextLine.measure(TextLine.java:296)
      at android.text.TextLine.metrics(TextLine.java:270)
      at android.text.Layout.getLineExtent(Layout.java:1075)
      at android.text.Layout.drawText(Layout.java:392)
      at android.widget.Editor.drawHardwareAccelerated(Editor.java:1585)
      at android.widget.Editor.onDraw(Editor.java:1507)
      at android.widget.TextView.onDraw(TextView.java:5715)
      at android.view.View.draw(View.java:16178)
      at android.view.View.updateDisplayListIfDirty(View.java:15174)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.draw(View.java:16181)
      at android.view.View.updateDisplayListIfDirty(View.java:15174)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.updateDisplayListIfDirty(View.java:15169)
      at android.view.View.draw(View.java:15948)
      at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
      at android.view.View.draw(View.java:16181)
      at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
      at android.view.View.updateDisplayListIfDirty(View.java:15174)
      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
      at android.view.Choreographer.doCallbacks(Choreographer.java:670)
      at android.view.Choreographer.doFrame(Choreographer.java:606)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit

虽然我认为Fragment是问题所在。但是这里的片段有一个目的,可供多个Activity使用。 所以我在这里锁定了这个解决方案,但未能让它对我有用。 任何建议都将不胜感激。

这是代码:

活性:

    public class APackageActivity extends CustomActivity {
        private String community = "community";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_apackage);

            updateNotices();
        }

        private void updateNotices() {
            Button button = (Button) findViewById(R.id.package_notice_normal);
            button.setText(R.string.package_notice_normal);
            button.append(String.format(Locale.getDefault(), "%d件", 5));
            button = (Button) findViewById(R.id.package_notice_transfer);
            button.setText(R.string.package_notice_transfer);
            button.append(String.format(Locale.getDefault(), "%d件", 4));
            button = (Button) findViewById(R.id.package_notice_pay);
            button.setText(R.string.package_notice_pay);
            button.append(String.format(Locale.getDefault(), "%d件", 3));
            button = (Button) findViewById(R.id.package_notice_alert);
            button.setText(R.string.package_notice_alert);
            button.append(String.format(Locale.getDefault(), "%d件", 2));
            button = (Button) findViewById(R.id.package_notice_overtime);
            button.setText(R.string.package_notice_overtime);
            button.append(String.format(Locale.getDefault(), "%d件", 1));
        }

        public void untaken(View arg0) {
            Intent intent = new Intent(this, APackageSearchListActivity.class);
            startActivity(intent);
            finish();
        }

        public void newPackage(View arg0) {
            Intent intent = new Intent(this, APackageNewActivity.class);
            startActivity(intent);
            finish();
        }

        public void newCashOnDelivery(View arg0) {
            Intent intent = new Intent(this, APackageCashOnDeliveryNewActivity.class);
            startActivity(intent);
            finish();
        }

        public void newTransfer(View arg0) {
            Intent intent = new Intent(this, APackageTransferActivity.class);
            startActivity(intent);
            finish();
        }

        public void take(View arg0) {
            Intent intent = new Intent(this, APackageTakeActivity.class);
            startActivity(intent);
            finish();
        }

        public void packageHome(View arg0) {
            Intent intent = new Intent(this, AffairsActivity.class);
            startActivity(intent);
            finish();
        }

        public void home(View arg0) {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }

        public void logout(View arg0) {
            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    }

活动布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="life.i_cloud.beebox.APackageActivity"
        android:background="@drawable/bg"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/package_search_bar_height"
            android:background="@drawable/notification_template_icon_bg"
            android:paddingBottom="@dimen/title_padding_bottom"
            android:paddingStart="@dimen/title_padding_lef_right"
            android:paddingEnd="@dimen/title_padding_lef_right"
            android:paddingTop="@dimen/title_padding_top">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_title"
                android:id="@+id/txtTitle"
                android:textSize="@dimen/activity_40sp"
                android:layout_gravity="center_vertical"
                android:layout_marginEnd="@dimen/search_spilt_padding" />

            <fragment
                android:name="life.i_cloud.beebox.PackageSearchBar"
                android:layout_weight="1"
                tools:layout="@layout/package_search_bar"
                android:id="@+id/package_search_fragment"
                android:layout_width="0dp"
                android:layout_height="match_parent" />

        </LinearLayout>

        <RelativeLayout android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginBottom="@dimen/package_menu_area_margin_top_bottom"
            android:layout_marginTop="@dimen/package_menu_area_margin_top_bottom"
            android:layout_marginStart="@dimen/package_menu_area_margin_left_right"
            android:layout_marginEnd="@dimen/package_menu_area_margin_left_right">

            <GridLayout
                android:layout_width="@dimen/package_notice_area_width"
                android:layout_height="@dimen/package_notice_area_height"
                android:columnCount="2"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true">

                <Button
                    android:layout_width="@dimen/activity_200dp"
                    android:layout_height="@dimen/activity_40dp"
                    android:text="@string/package_notice_normal"
                    android:textSize="@dimen/activity_20sp"
                    android:background="@drawable/btn_blue"
                    android:textColor="@android:color/white"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="top|end"
                    android:paddingStart="@dimen/package_notice_padding_left"
                    android:paddingBottom="@dimen/package_notice_padding_top_bottom"
                    android:paddingEnd="@dimen/package_notice_padding_right"
                    android:paddingTop="@dimen/package_notice_padding_top_bottom"
                    android:onClick="untaken"
                    android:id="@+id/package_notice_normal" />

                <Button
                    android:layout_width="@dimen/activity_200dp"
                    android:layout_height="@dimen/activity_40dp"
                    android:text="@string/package_notice_transfer"
                    android:id="@+id/package_notice_transfer"
                    android:textSize="@dimen/activity_20sp"
                    android:background="@drawable/btn_orange"
                    android:textColor="@android:color/white"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="top|end"
                    android:paddingStart="@dimen/package_notice_padding_left"
                    android:paddingBottom="@dimen/package_notice_padding_top_bottom"
                    android:paddingEnd="@dimen/package_notice_padding_right"
                    android:paddingTop="@dimen/package_notice_padding_top_bottom"
                    android:onClick="untaken" />

                <Button
                    android:layout_width="@dimen/activity_200dp"
                    android:layout_height="@dimen/activity_40dp"
                    android:text="@string/package_notice_pay"
                    android:id="@+id/package_notice_pay"
                    android:textSize="@dimen/activity_20sp"
                    android:background="@drawable/btn_purple"
                    android:textColor="@android:color/white"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="top|end"
                    android:paddingStart="@dimen/package_notice_padding_left"
                    android:paddingBottom="@dimen/package_notice_padding_top_bottom"
                    android:paddingEnd="@dimen/package_notice_padding_right"
                    android:paddingTop="@dimen/package_notice_padding_top_bottom"
                    android:onClick="untaken" />

                <Button
                    android:layout_width="@dimen/activity_200dp"
                    android:layout_height="@dimen/activity_40dp"
                    android:text="@string/package_notice_alert"
                    android:id="@+id/package_notice_alert"
                    android:textSize="@dimen/activity_20sp"
                    android:background="@drawable/btn_red"
                    android:textColor="@android:color/white"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="top|end"
                    android:paddingStart="@dimen/package_notice_padding_left"
                    android:paddingBottom="@dimen/package_notice_padding_top_bottom"
                    android:paddingEnd="@dimen/package_notice_padding_right"
                    android:paddingTop="@dimen/package_notice_padding_top_bottom"
                    android:onClick="untaken" />

                <Button
                    android:layout_width="@dimen/activity_200dp"
                    android:layout_height="@dimen/activity_40dp"
                    android:text="@string/package_notice_overtime"
                    android:id="@+id/package_notice_overtime"
                    android:textSize="@dimen/activity_20sp"
                    android:background="@drawable/btn_green"
                    android:textColor="@android:color/white"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="top|end"
                    android:paddingStart="@dimen/package_notice_padding_left"
                    android:paddingBottom="@dimen/package_notice_padding_top_bottom"
                    android:paddingEnd="@dimen/package_notice_padding_right"
                    android:paddingTop="@dimen/package_notice_padding_top_bottom"
                    android:onClick="untaken" />
            </GridLayout>

            <GridLayout
                android:layout_width="@dimen/package_menu_area_width"
                android:layout_height="@dimen/package_menu_area_height"
                android:columnCount="3"
                android:layout_gravity="bottom"
                android:layout_alignParentBottom="true"
                android:layout_alignParentStart="true">

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_APackage_New"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="newPackage" />

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_APackage_Take_Pay"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="newCashOnDelivery" />

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_APackage_Transfer"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="newTransfer" />

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_APackage_Take"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="take" />

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_AffairsMain"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="packageHome" />

                <Button
                    android:layout_width="@dimen/package_menu_button_width"
                    android:layout_height="@dimen/package_menu_button_height"
                    android:text="@string/btn_home"
                    android:background="@drawable/btn_bg"
                    android:textSize="@dimen/package_menu_text_size"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    android:layout_gravity="bottom|start"
                    android:onClick="home" />

            </GridLayout>

            <Button
                android:layout_width="@dimen/package_menu_button_width"
                android:layout_height="@dimen/package_menu_button_height"
                android:text="@string/btn_logout"
                android:id="@+id/btnLogout"
                android:background="@drawable/btn_bg"
                android:textSize="@dimen/activity_20sp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentEnd="true"
                android:onClick="logout" />
        </RelativeLayout>

    </LinearLayout>

片段:

    public class PackageSearchBar extends Fragment implements View.OnClickListener {
        private String community;
        private TextView label1, label2, label3;
        private Spinner searchType, searchStatus, search1, search2, search3;
        private PackageAddressSearchRoadAdapter addressRoadAdapter;
        private PackageAddressSearchFloorAdapter addressFloorAdapter;
        private PackageAddressSearchDepartmentIdAdapter addressDepartmentIdAdapter;
        private PackageDepartmentSearchBuildingIdAdapter departmentBuildingIdAdapter;
        private PackageDepartmentSearchFloorAdapter departmentFoorAdapter;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle bundle) {
            return inflater.inflate(R.layout.package_search_bar, parent, false);
        }

        @Override
        public void onActivityCreated(Bundle bundle) {
            super.onActivityCreated(bundle);
            View view = getView();
            searchType = (Spinner) view.findViewById(R.id.package_searchType);
            searchStatus = (Spinner) view.findViewById(R.id.package_searchStatus);
            search1 = (Spinner) view.findViewById(R.id.package_search1);
            search2 = (Spinner) view.findViewById(R.id.package_search2);
            search3 = (Spinner) view.findViewById(R.id.package_search3);
            label1 = (TextView) view.findViewById(R.id.package_label1);
            label2 = (TextView) view.findViewById(R.id.package_label2);
            label3 = (TextView) view.findViewById(R.id.package_label3);
            addressRoadAdapter = new PackageAddressSearchRoadAdapter(community);
            addressFloorAdapter = new PackageAddressSearchFloorAdapter(community);
            addressDepartmentIdAdapter = new PackageAddressSearchDepartmentIdAdapter(community);
            departmentBuildingIdAdapter = new PackageDepartmentSearchBuildingIdAdapter(community);
            departmentFoorAdapter = new PackageDepartmentSearchFloorAdapter(community);

            searchType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    switch (position) {
                        case 0: //地址搜尋
                            label1.setText(R.string.package_road);
                            label2.setText(R.string.package_floor);
                            search1.setAdapter(addressRoadAdapter);
                            search2.setAdapter(addressFloorAdapter);
                            label3.setVisibility(View.VISIBLE);
                            search3.setVisibility(View.VISIBLE);
                            break;
                        case 1: //戶號搜尋
                            label1.setText(R.string.package_building_id);
                            label2.setText(R.string.package_floor_number);
                            search1.setAdapter(departmentBuildingIdAdapter);
                            search2.setAdapter(departmentFoorAdapter);
                            label3.setVisibility(View.GONE);
                            search3.setVisibility(View.GONE);
                            break;
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
            label1.setText(R.string.package_road);
            label2.setText(R.string.package_floor);
            label3.setText(R.string.package_department_id);
            search1.setAdapter(addressRoadAdapter);
            search2.setAdapter(addressFloorAdapter);
            search3.setAdapter(addressDepartmentIdAdapter);

            view.findViewById(R.id.package_search).setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            Activity activity = getActivity();
            Intent intent = new Intent(activity, APackageSearchActivity.class);
            startActivity(intent);
            activity.finish();
        }
    }

片段布局:

    <?xml version="1.0" encoding="utf-8"?>
    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:gravity="center_vertical"
            android:layout_gravity="top">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_search_type"
                android:paddingStart="@dimen/search_padding_left_right"
                android:paddingEnd="@dimen/search_padding_left_right" />

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/package_searchType"
                android:spinnerMode="dropdown"
                android:entries="@array/package_search_type_list"
                android:layout_weight="1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_status"
                android:paddingStart="@dimen/search_padding_left_right"
                android:paddingEnd="@dimen/search_padding_left_right" />

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/package_searchStatus"
                android:spinnerMode="dropdown"
                android:entries="@array/package_search_status_list"
                android:layout_weight="1" />

        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="1"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:gravity="center_vertical"
            android:layout_gravity="bottom">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_road"
                android:id="@+id/package_label1"
                android:paddingStart="@dimen/search_padding_left_right"
                android:paddingEnd="@dimen/search_padding_left_right" />

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/package_search1"
                android:spinnerMode="dropdown"
                android:layout_weight="1"
                android:entries="@array/package_search_road_list" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_floor"
                android:id="@+id/package_label2"
                android:paddingStart="@dimen/search_padding_left_right"
                android:paddingEnd="@dimen/search_padding_left_right" />

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/package_search2"
                android:spinnerMode="dropdown"
                android:layout_weight="1"
                android:entries="@array/package_search_address_floor_list" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/package_department_id"
                android:id="@+id/package_label3"
                android:paddingStart="@dimen/search_padding_left_right"
                android:paddingEnd="@dimen/search_padding_left_right" />

            <Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/package_search3"
                android:spinnerMode="dropdown"
                android:layout_weight="1"
                android:entries="@array/package_search_department_id_list" />
        </LinearLayout>

        <Button
            android:layout_width="@dimen/activity_80dp"
            android:layout_height="@dimen/activity_40dp"
            android:text="@string/btn_search"
            android:background="@drawable/btn_bg"
            android:layout_rowSpan="2"
            android:layout_row="0"
            android:layout_gravity="center_vertical"
            android:layout_column="2"
            android:layout_marginStart="@dimen/search_spilt_padding"
            android:id="@+id/package_search" />

    </GridLayout>

CustomActivity:

    public class CustomActivity extends AppCompatActivity {
        protected CustomActivity myself;
        private boolean runFlag = true;
        private static InputMethodManager im = null;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Locale.setDefault(new Locale("zh", "TW"));
            myself = this;
            if (im == null) {
                im = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
            }
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
        @Override
        protected void onStart() {
            super.onStart();

            if (runFlag) {
                ViewGroup rootLayout = (ViewGroup) getWindow().getDecorView();
                FontManager.changeFonts(rootLayout, this); // change all the text font in the page
                runFlag = false;
            }

        }

        protected void showToast(final String text) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(myself, text, Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        protected void onResume() {
            super.onResume();


            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            );
        }
    }

1 个答案:

答案 0 :(得分:0)

我发现Activity.updateNotices在setText by source之后使用Buttons上的追加字符串导致了崩溃。所以我所做的就是首先通过源获取String。将其与想要追加的字符串合并。然后使用setText修改按钮上的文本。问题解决了。

我修改如下:

private void updateNotices() {
    Button button = (Button) findViewById(R.id.package_notice_normal);
    button.setText(getResources().getString(R.string.package_notice_normal) + 5 + "件");
    button = (Button) findViewById(R.id.package_notice_transfer);
    button.setText(getResources().getString(R.string.package_notice_transfer) + 4 + "件");
    button = (Button) findViewById(R.id.package_notice_pay);
    button.setText(getResources().getString(R.string.package_notice_pay) + 3 + "件");
    button = (Button) findViewById(R.id.package_notice_alert);
    button.setText(getResources().getString(R.string.package_notice_alert) + 2 + "件");
    button = (Button) findViewById(R.id.package_notice_overtime);
    button.setText(getResources().getString(R.string.package_notice_overtime) + 1 + "件");
}