Android 在片段上调用onClickListener的正确方法

Android 在片段上调用onClickListener的正确方法,android,view,android-fragments,onclick,onclicklistener,Android,View,Android Fragments,Onclick,Onclicklistener,我正在开发一个包含自定义拨号程序片段的应用程序。此片段的功能应与股票拨号器相同。当我按下一个按钮时,这个数字就会出现在editText窗口中,就这么简单 但是,编辑文本上没有显示数字。我第一次尝试使用活动而不是片段,效果很好。现在,我被迫将活动更改为片段,并根据片段eviroment修改代码,但此功能不起作用 这是PhoneView片段: public class PhoneView extends Fragment implements OnTabChangeListener, OnClick

我正在开发一个包含自定义拨号程序片段的应用程序。此片段的功能应与股票拨号器相同。当我按下一个按钮时,这个数字就会出现在editText窗口中,就这么简单

但是,编辑文本上没有显示数字。我第一次尝试使用活动而不是片段,效果很好。现在,我被迫将活动更改为片段,并根据片段eviroment修改代码,但此功能不起作用

这是
PhoneView
片段:

public class PhoneView extends Fragment implements OnTabChangeListener, OnClickListener {

    ImageButton dialBtn;
    ImageButton clearBtn;
    EditText numTxt;
    ImageButton button1;
    ImageButton button2;
    ImageButton button3;
    ImageButton button4;
    ImageButton button5;
    ImageButton button6;
    ImageButton button7;
    ImageButton button8;
    ImageButton button9;
    ImageButton button0;
    ImageButton buttonstar;
    ImageButton buttonpound;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mRoot = inflater.inflate(R.layout.phone_view, null);

        dialBtn = (ImageButton) mRoot.findViewById(R.id.dialButton);
        clearBtn = (ImageButton) mRoot.findViewById(R.id.deleteButton);
        numTxt = (EditText) mRoot.findViewById(R.id.digits);
        button1 = (ImageButton) mRoot.findViewById(R.id.one);
        button2 = (ImageButton) mRoot.findViewById(R.id.two);
        button3 = (ImageButton) mRoot.findViewById(R.id.three);
        button4 = (ImageButton) mRoot.findViewById(R.id.four);
        button5 = (ImageButton) mRoot.findViewById(R.id.five);
        button6 = (ImageButton) mRoot.findViewById(R.id.six);
        button7 = (ImageButton) mRoot.findViewById(R.id.seven);
        button8 = (ImageButton) mRoot.findViewById(R.id.eight);
        button9 = (ImageButton) mRoot.findViewById(R.id.nine);
        button0 = (ImageButton) mRoot.findViewById(R.id.zero);
        buttonstar = (ImageButton) mRoot.findViewById(R.id.star);
        buttonpound = (ImageButton) mRoot.findViewById(R.id.pound);

        dialBtn.setOnClickListener(this);
        clearBtn.setOnClickListener(this);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
        button6.setOnClickListener(this);
        button7.setOnClickListener(this);
        button8.setOnClickListener(this);
        button9.setOnClickListener(this);
        button0.setOnClickListener(this);
        buttonstar.setOnClickListener(this);
        buttonpound.setOnClickListener(this);

        return mRoot;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dialButton:
                startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + numTxt.getText())));
                break;
            case R.id.deleteButton:
                String contents = numTxt.getText().toString();
                if (contents.length() > 0) {
                    numTxt.setText(contents.substring(0, contents.length()-1));
                }
                break;
            case R.id.one:
                numTxt.setText(numTxt.getText()+"1");
                break;
            case R.id.two:
                numTxt.setText(numTxt.getText()+"2");
                break;
            case R.id.three:
                numTxt.setText(numTxt.getText()+"3");
                break;
            case R.id.four:
                numTxt.setText(numTxt.getText()+"4");
                break;
            case R.id.five:
                numTxt.setText(numTxt.getText()+"5");
                break;
            case R.id.six:
                numTxt.setText(numTxt.getText()+"6");
                break;
            case R.id.seven:
                numTxt.setText(numTxt.getText()+"7");
                break;
            case R.id.eight:
                numTxt.setText(numTxt.getText()+"8");
                break;
            case R.id.nine:
                numTxt.setText(numTxt.getText()+"9");
                break;
            case R.id.zero:
                numTxt.setText(numTxt.getText()+"0");
                break;
            case R.id.star:
                numTxt.setText(numTxt.getText()+"*");
                break;
            case R.id.pound:
                numTxt.setText(numTxt.getText()+"#");
                break;
        }
比如说,拨号键起作用,但不起作用的是在编辑文本上显示按下的数字。这可能与片段的任何限制或特殊功能有关吗

更新->在上面和xml后面添加了更多代码

<!-- Layout for the dialer -->
<LinearLayout 
    android:id="@+id/Right_layout"
    android:layout_width="fill_parent"        
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_marginStart="@dimen/dialpad_horizontal_margin"
    android:background="#000000" > 

    <!-- Text field above the keypad where the digits are displayed -->
    <LinearLayout
        android:id="@+id/digits_container"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_digits"
        android:layout_marginTop="@dimen/dialpad_vertical_margin"
        android:gravity="center"
        android:background="@drawable/dialpad_background" >

        <EditText
            android:id="@+id/digits"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center"
            android:scrollHorizontally="true"
            android:textAppearance="@style/DialtactsDigitsTextAppearance"
            android:focusableInTouchMode="false"
            android:nextFocusRight="@+id/deleteButton"
            android:background="@android:color/transparent" 
            android:inputType="none" />

        <ImageButton
            android:id="@+id/deleteButton"
            android:layout_width="56dip"
            android:layout_height="50dip"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:contentDescription="@string/description_delete_button"
            android:src="@drawable/ic_dial_action_delete" 
            android:background="@drawable/dialbtn_push"/>
    </LinearLayout>

    <!-- The dialpad itself -->
    <include layout="@layout/dialpad" />

    <View
       android:layout_width="match_parent"
       android:layout_height="@dimen/dialpad_vertical_margin"
       android:background="#66000000"/>

    <FrameLayout
        android:id="@+id/dialButtonContainer"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/dialpad_background">

        <ImageButton
            android:id="@+id/dialButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@drawable/btn_call"
            android:contentDescription="@string/description_dial_button"
            android:src="@drawable/ic_dial_action_call" />

</FrameLayout>        
</LinearLayout>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialpad"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="@integer/dialpad_layout_weight_dialpad"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/dialpad_vertical_margin"
android:paddingStart="5dip"
android:paddingEnd="5dip"
android:paddingBottom="10dip"
android:background="@drawable/dialpad_background"
android:layoutDirection="ltr">

<TableRow
     android:layout_height="0px"
     android:layout_weight="1" >
    <ImageButton 
        android:id="@+id/one" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_1_no_vm_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_one" />
    <ImageButton 
        android:id="@+id/two" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_2_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_two" />
    <ImageButton 
        android:id="@+id/three" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_3_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_three" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/four" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_4_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_four" />
    <ImageButton 
        android:id="@+id/five" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_5_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_five" />
    <ImageButton 
        android:id="@+id/six" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_6_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_six" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/seven" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_7_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_seven" />
    <ImageButton 
        android:id="@+id/eight" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_8_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_eight" />
    <ImageButton 
        android:id="@+id/nine" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_9_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_nine" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/star" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_star_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_star" />
    <ImageButton 
        android:id="@+id/zero" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_0_no_plus_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_zero" />
    <ImageButton 
        android:id="@+id/pound" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_pound_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_pound" />
</TableRow>
phone_view.xml

<!-- Layout for the dialer -->
<LinearLayout 
    android:id="@+id/Right_layout"
    android:layout_width="fill_parent"        
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_marginStart="@dimen/dialpad_horizontal_margin"
    android:background="#000000" > 

    <!-- Text field above the keypad where the digits are displayed -->
    <LinearLayout
        android:id="@+id/digits_container"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_digits"
        android:layout_marginTop="@dimen/dialpad_vertical_margin"
        android:gravity="center"
        android:background="@drawable/dialpad_background" >

        <EditText
            android:id="@+id/digits"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center"
            android:scrollHorizontally="true"
            android:textAppearance="@style/DialtactsDigitsTextAppearance"
            android:focusableInTouchMode="false"
            android:nextFocusRight="@+id/deleteButton"
            android:background="@android:color/transparent" 
            android:inputType="none" />

        <ImageButton
            android:id="@+id/deleteButton"
            android:layout_width="56dip"
            android:layout_height="50dip"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:contentDescription="@string/description_delete_button"
            android:src="@drawable/ic_dial_action_delete" 
            android:background="@drawable/dialbtn_push"/>
    </LinearLayout>

    <!-- The dialpad itself -->
    <include layout="@layout/dialpad" />

    <View
       android:layout_width="match_parent"
       android:layout_height="@dimen/dialpad_vertical_margin"
       android:background="#66000000"/>

    <FrameLayout
        android:id="@+id/dialButtonContainer"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/dialpad_background">

        <ImageButton
            android:id="@+id/dialButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@drawable/btn_call"
            android:contentDescription="@string/description_dial_button"
            android:src="@drawable/ic_dial_action_call" />

</FrameLayout>        
</LinearLayout>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialpad"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="@integer/dialpad_layout_weight_dialpad"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/dialpad_vertical_margin"
android:paddingStart="5dip"
android:paddingEnd="5dip"
android:paddingBottom="10dip"
android:background="@drawable/dialpad_background"
android:layoutDirection="ltr">

<TableRow
     android:layout_height="0px"
     android:layout_weight="1" >
    <ImageButton 
        android:id="@+id/one" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_1_no_vm_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_one" />
    <ImageButton 
        android:id="@+id/two" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_2_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_two" />
    <ImageButton 
        android:id="@+id/three" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_3_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_three" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/four" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_4_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_four" />
    <ImageButton 
        android:id="@+id/five" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_5_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_five" />
    <ImageButton 
        android:id="@+id/six" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_6_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_six" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/seven" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_7_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_seven" />
    <ImageButton 
        android:id="@+id/eight" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_8_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_eight" />
    <ImageButton 
        android:id="@+id/nine" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_9_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_nine" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/star" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_star_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_star" />
    <ImageButton 
        android:id="@+id/zero" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_0_no_plus_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_zero" />
    <ImageButton 
        android:id="@+id/pound" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_pound_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_pound" />
</TableRow>

dialpad.xml

<!-- Layout for the dialer -->
<LinearLayout 
    android:id="@+id/Right_layout"
    android:layout_width="fill_parent"        
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_marginStart="@dimen/dialpad_horizontal_margin"
    android:background="#000000" > 

    <!-- Text field above the keypad where the digits are displayed -->
    <LinearLayout
        android:id="@+id/digits_container"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_digits"
        android:layout_marginTop="@dimen/dialpad_vertical_margin"
        android:gravity="center"
        android:background="@drawable/dialpad_background" >

        <EditText
            android:id="@+id/digits"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center"
            android:scrollHorizontally="true"
            android:textAppearance="@style/DialtactsDigitsTextAppearance"
            android:focusableInTouchMode="false"
            android:nextFocusRight="@+id/deleteButton"
            android:background="@android:color/transparent" 
            android:inputType="none" />

        <ImageButton
            android:id="@+id/deleteButton"
            android:layout_width="56dip"
            android:layout_height="50dip"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:contentDescription="@string/description_delete_button"
            android:src="@drawable/ic_dial_action_delete" 
            android:background="@drawable/dialbtn_push"/>
    </LinearLayout>

    <!-- The dialpad itself -->
    <include layout="@layout/dialpad" />

    <View
       android:layout_width="match_parent"
       android:layout_height="@dimen/dialpad_vertical_margin"
       android:background="#66000000"/>

    <FrameLayout
        android:id="@+id/dialButtonContainer"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="@integer/dialpad_layout_weight_additional_buttons"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/dialpad_background">

        <ImageButton
            android:id="@+id/dialButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@drawable/btn_call"
            android:contentDescription="@string/description_dial_button"
            android:src="@drawable/ic_dial_action_call" />

</FrameLayout>        
</LinearLayout>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialpad"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="@integer/dialpad_layout_weight_dialpad"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/dialpad_vertical_margin"
android:paddingStart="5dip"
android:paddingEnd="5dip"
android:paddingBottom="10dip"
android:background="@drawable/dialpad_background"
android:layoutDirection="ltr">

<TableRow
     android:layout_height="0px"
     android:layout_weight="1" >
    <ImageButton 
        android:id="@+id/one" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_1_no_vm_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_one" />
    <ImageButton 
        android:id="@+id/two" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_2_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_two" />
    <ImageButton 
        android:id="@+id/three" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_3_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_three" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/four" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_4_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_four" />
    <ImageButton 
        android:id="@+id/five" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_5_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_five" />
    <ImageButton 
        android:id="@+id/six" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_6_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_six" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/seven" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_7_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_seven" />
    <ImageButton 
        android:id="@+id/eight" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_8_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_eight" />
    <ImageButton 
        android:id="@+id/nine" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_9_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_nine" />
</TableRow>

<TableRow
     android:layout_height="0px"
     android:layout_weight="1">
    <ImageButton 
        android:id="@+id/star" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_star_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_star" />
    <ImageButton 
        android:id="@+id/zero" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_0_no_plus_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_zero" />
    <ImageButton 
        android:id="@+id/pound" 
        style="@style/DialpadButtonStyle"
        android:src="@drawable/dial_num_pound_wht"
        android:background="@drawable/dialbtn_push"
        android:contentDescription="@string/description_image_button_pound" />
</TableRow>


声明
numText
为类成员。你有

EditText numTxt = (EditText) mRoot.findViewById(R.id.digits);
// local to onCreateView
改为

EditText numTxt;
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mRoot = inflater.inflate(R.layout.phone_view, null);

        ImageButton dialBtn = (ImageButton) mRoot.findViewById(R.id.dialButton);
        ImageButton clearBtn = (ImageButton) mRoot.findViewById(R.id.deleteButton);
        numTxt = (EditText) mRoot.findViewById(R.id.digits);
编辑:更新后的问题

正如我在评论中所说的,我认为发布的代码没有任何问题

既然你说不能将文本设置为editText,我就运行了你的代码。出于测试目的,我将启动器图标设置为背景,设置为
ImageButton
。为了测试的目的,我修改了ui

但逻辑和你用的一样


以这种方式更新,但仍然不起作用。使用带有片段的editText有什么问题吗?我投入了一点资金,似乎用片段动态更新edittext会导致此类问题。。但是,如何选择它?@masmic_87检查您的编辑文本是否正确初始化。不是碎片的错,我正试图理解为什么不适合我,但我快疯了!谢谢你的帮助。我会再投资一点,看看是否能找到原因。如果我发现了什么,我会发布一个新的问题你不会相信的。。。我发现发生了什么事!文本与背景颜色相同。。。这就是为什么我看不到。。。LOL@masmic_87哇!这就是为什么如果我改变用户界面,它对我有效。下次将文本设置为edittext in xml,并在图形编辑器中检查其是否可见。你昨天发布了相同的问题是的,我一直在寻找解决方案,但没有。。。我试图改变一些事情,这就是我提出新问题的方式。声明与我昨天的方式有些不同。@masmic_87如果重复,您可以随时编辑您的问题。你没有得到一个解决方案你可以提供一个赏金我会删除昨天的问题,我认为这有更多的代码,问题更清楚