2013-03-25 10 views
2

在onCreate方法中TextWatcher的實現不起作用,我嘗試使用虛擬鍵盤和硬件鍵盤進行文本輸入,並嘗試了模擬器和真實設備上的代碼。似乎沒有任何工作。TextWatcher不能正常工作,出現什麼問題

我甚至改名佈局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> 
+0

的衝突,哪裏是你的'ShowToast()'函數? – 2013-03-25 13:38:53

+0

它如何「不起作用」?你有什麼嘗試?你看到錯誤還是敬酒不顯示?你的ShowToast方法是什麼樣的?你有沒有試過打印日誌語句?如果將toast/log和resetTimeout調用移動到onTextChanged會發生什麼? – Sababado 2013-03-25 13:40:13

+0

我添加了ShowToast – 2013-03-25 13:50:50

回答

3

中的EditText的命名與其他佈局 衝突的我改名兩種佈局的EditTexts,然後清洗項目 一切工作現在 谷歌必須做些什麼阿多諾的的命名對不同的佈局

0

嘗試改變從getApplicationContext(上下文),以ActivityName.this

+0

問題不在showtoast()它是在聽衆 – 2013-03-25 17:18:38