TextWatcher не работает, что не так

Реализация TextWatcher в методе onCreate не работает, я пробовал вводить текст с использованием виртуальной клавиатуры и присутствующей аппаратной клавиатуры, также пробовал код на эмуляторе и реальном устройстве. вроде ничего не работает.

я даже переименовал EditTexts в макете и очистил проект, перестроил его, без надежды

любая идея?

вот код

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.remarks);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    Intent i = getIntent();
    Current_Language = i.getStringExtra("Lang");
    Q1Rate = i.getFloatExtra("Q1Rate", 0f);
    Q2Rate = i.getFloatExtra("Q2Rate", 0f);
    Q3Rate = i.getFloatExtra("Q3Rate", 0f);
    Q4Rate = i.getFloatExtra("Q4Rate", 0f);
    Q5Rate = i.getFloatExtra("Q5Rate", 0f);
    LoadSettings();
    NextBtnState();
    final EditText edt_PhoneNo     = (EditText) findViewById(R.id.edt_Remarks_PhoneNo);
    final EditText edt_Suggestions = (EditText) findViewById(R.id.edt_Remarks_Suggestion);
    edt_Suggestions.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
        public void afterTextChanged(Editable s) {
            ShowToast("I Am Here Firas");
            resetTimeout();
        }
    });
    edt_PhoneNo.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
        public void afterTextChanged(Editable s) {
            ShowToast("I Am Here Firas");
            resetTimeout();
        }
    });
}

вот мой ShowToast

public void ShowToast (String Msg) {
    Context context = getApplicationContext();
    CharSequence text = Msg;
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(context, text, duration);
    toast.setGravity(Gravity.CENTER|Gravity.CENTER, 0, 0);
    toast.show();
}

а вот макет

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Azure1"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:orientation="vertical" >

<GridLayout
    android:id="@+id/Grid1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:columnCount="4"
    android:rowCount="4" >

    <Space
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/img_ClientLogo"
        android:layout_width="275dp"
        android:layout_height="145dp"
        android:layout_gravity="left"
        android:src="@drawable/general_client_logo" />

    <TextView
        android:id="@+id/tv_CustomerSatisfactionSurvey"
        android:layout_width="948dp"
        android:layout_height="103dp"
        android:layout_column="3"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:layout_row="0"
        android:gravity="center"
        android:text="@string/Customer_Satisfaction_Survey"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/OrangeRed2"
        android:textSize="50sp" />
</GridLayout>

<RelativeLayout
    android:id="@+id/ly_Stars"
    android:layout_width="match_parent"
    android:layout_height="379dp">

    <EditText
        android:id="@+id/edt_Remarks_PhoneNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_Remarks_PhoneNo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:hint="@string/Mobile_No"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/tv_Remarks_Suggestions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edt_Remarks_PhoneNo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp"
        android:text="@string/Any_Comment"
        android:textSize="25sp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/edt_Remarks_Suggestion"
        android:layout_width="590dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_Remarks_Suggestions"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:hint="@string/suggestion"
        android:inputType="textCapSentences|textMultiLine"
        android:singleLine="false" />

    <TextView
        android:id="@+id/tv_Remarks_PhoneNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:text="@string/Phone_Account_No"
        android:textSize="25sp"
        android:textStyle="bold" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/ly_NextPrevios"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <Button
        android:id="@+id/btn_Next"
        style="@style/ButtonText"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:layout_above="@+id/tv_PoweredBy"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="45dp"
        android:background="@drawable/btn_blue"
        android:drawableRight="@drawable/arrow_right"
        android:onClick="Next_Page"
        android:text="@string/btn_Next" />

    <TextView
        android:id="@+id/tv_PoweredBy"
        android:layout_width="772dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="@string/powerd_by_prime"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16sp" />

    <Button
        android:id="@+id/btn_Previous"
        style="@style/ButtonText"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:layout_above="@+id/tv_PoweredBy"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="45dp"
        android:background="@drawable/btn_blue"
        android:drawableLeft="@drawable/arrow_left"
        android:onClick="Previous_Page"
        android:text="@string/btn_Previous" />

    <ImageView
        android:id="@+id/img_help"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignBottom="@+id/btn_Previous"
        android:layout_centerHorizontal="true"
        android:onClick="ShowHelpDialog"
        android:src="@drawable/help_64" />

    <TextView
        android:id="@+id/tv_Steps"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/progressBar1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:text="@string/Step6of6"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="650dp"
        android:layout_height="20dp"
        android:layout_above="@+id/img_help"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:max="6"
        android:progress="6"
        android:progressDrawable="@drawable/my_progress" />

</RelativeLayout>

</LinearLayout>

person Firas Shrourou    schedule 25.03.2013    source источник
comment
А где твоя ShowToast() функция?   -  person    schedule 25.03.2013
comment
Как это не работает? Что ты пробовал? Вы видите ошибки или не показываются тосты? Как выглядит ваш метод ShowToast? Вы пробовали печатать отчеты журнала? Что произойдет, если вы переместите вызовы тоста / журнала и resetTimeout в onTextChanged?   -  person Sababado    schedule 25.03.2013
comment
Я добавил ShowToast   -  person Firas Shrourou    schedule 25.03.2013
comment
без ошибок, просто ничего не происходит, без тостов   -  person Firas Shrourou    schedule 25.03.2013
comment
Можете ли вы также опубликовать файл макета примечаний?   -  person user    schedule 25.03.2013
comment
Вы пробовали печатать отчеты журнала? Что произойдет, если вы переместите вызовы тоста / журнала и resetTimeout в onTextChanged?   -  person Sababado    schedule 25.03.2013


Ответы (2)


Именование EditText противоречило другому макету, поэтому я переименовал EditTexts в обоих макетах, а затем очистил проект, теперь все работает. Google должен что-то сделать с конфликтом именования просмотров на разных макетах.

person Firas Shrourou    schedule 27.03.2013

Попробуйте изменить контекст с getApplicationContext () на ActivityName.this

person Neha Nathani    schedule 25.03.2013