Fragment中的setText TextView不会显示更新

时间:2017-07-13 22:00:32

标签: android user-interface android-fragments textview

我有一个传递给它的包的片段。捆绑包通过(使用Log标签验证)和代码中的textView更新(我知道这是因为我应该更新TextView之后的I Log getText)。我的问题是视觉表现(屏幕)没有显示更新。

            numberView = (TextView) getActivity().findViewById(R.id.textView20);

            //From CantactLog()
            Bundle arguments = getArguments();
            if ( arguments!= null) {
                sName = getArguments().getString("sName");
                sNumber = getArguments().getString("sNumber");

                if (sNumber != null){
                    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                    String formatedNumber = null;
                    try {
                        Phonenumber.PhoneNumber numberProto = phoneUtil.parse(sNumber, "US");
                        //Since you know the country you can format it as follows:
                        formatedNumber = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);

                    } catch (NumberParseException e) {
                        System.err.println("NumberParseException was thrown: " + e.toString());
                    }
                    Log.i(TAG, " Formated Number " + formatedNumber);
                    sNumber= formatedNumber;

                    numberView.setText(sNumber);
                    // mPhoneSearch.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
                    scallName = sName;
                    Log.i(TAG, "sNumber = "+sNumber);
                    Log.i(TAG,"get text =" + numberView.getText().toString());

                }

            }

退出:

I / GifHeaderParser:Formated Number(650)555-1212

I / GifHeaderParser:sNumber =(650)555-1212

I / GifHeaderParser:get text =(650)555-1212

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/home_background"

    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:gravity="center"
    android:orientation="vertical"
    android:tag="landingFragmentTag">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView20"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="TextView" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="15dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/phoneSearch222"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:background="@drawable/edit_text_box"
                android:ems="10"
                android:hint="@string/search_by_phone_number"

                android:inputType="phone"
                android:lines="1"
                android:maxLength="14"
                android:textAlignment="center" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">


            <Button
                android:id="@+id/button2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:text="Choose from Contacts" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="25dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <Spinner
                android:id="@+id/call_log"
                style="@android:style/Widget.DropDownItem.Spinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="5dp"


                android:layout_marginRight="5dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/edit_text_box"
                android:minHeight="50dp"


                android:spinnerMode="dialog" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/animatedLayout"
            android:layout_width="fill_parent"

            android:layout_height="50dp"
            android:layout_marginBottom="15dp"

            android:layout_marginTop="15dp"
            android:orientation="vertical">

            <Button
                android:id="@+id/PhoneSearch"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"

                android:layout_marginBottom="2dp"

                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="2dp"
                android:backgroundTint="@android:color/holo_orange_light"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="@string/search_phone_number"
                android:textColor="@color/cardview_dark_background"
                android:visibility="visible" />
    </LinearLayout>

1 个答案:

答案 0 :(得分:0)

所以我回答了我自己的问题,当我调用片段打开时,我在片段传输中使用.add而不是.replace。