Reputation: 715
The implementation of TextWatcher in the onCreate method is not working, I tried doing text typing using virtual keyboard and hardware keyboard present, also tried the code on emulator and real device. nothing seems to work.
i even renamed the EditTexts in the layout and clean the project, re-build it, no hope
any idea?
here is the code
@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();
}
});
}
here is my 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();
}
and here is the layout
<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>
Upvotes: 3
Views: 5077
Reputation: 715
The naming of the EditText was conflicting with another layout so I renamed the EditTexts in both the layouts and then cleaned the project, everything works now. Google must do something about the conflict of the naming of Views on different layouts
Upvotes: 3
Reputation: 544
Try changing the context from getApplicationContext() to ActivityName.this
Upvotes: 0