This my activity_main.xml
<EditText
android:layout_width="200dp"
android:layout_height="100dp"
android:hint="@string/str3"
android:id="@+id/line2"
android:layout_below="@id/line1" />
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_toRightOf="@id/line2"
android:layout_below="@id/line1"
android:text="@string/str4"
android:onClick="method2"/>
I want to display the text entered in another activity but not in the way as done on the Activity tutorial (where another TextView is created in second activity and text set there only).
This is my display2.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display2);
Intent intent2 = getIntent();
This is in my activity_display2.xml
<TextView
android:id="@+id/pwdisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold|italic"
android:padding="30dp"
/>
and this is what I am trying to do (in main_activity.java)
public void method2(View view) {
Intent intent2 = new Intent(this, display2.class);
EditText enteredpw = (EditText) findViewById(R.id.line2);
String pw = enteredpw.getText().toString();
findViewById(R.id.pwdisplay).setText(pw); <--Error here
startActivity(intent2);
}
I am trying to set the text for pwdisplay TextView in main_activity.java itself, but got an error "cannot resolve method setText(java.lang.String)".
OR
is there any other way in which the text entered in EditText @id/line2 by the user, can be displayed by activity_display2.xml?
Error heredoes not say anything. Please post exact stack-trace.pwin intent object and fetchpwformintent2and initialize text view there and set data using setText