Edittext, on submit need to show on another window in android



In android,i want to get a string from user using EditText and on click of submit button the string need to be show on another page/pane.


here is my fragment.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText android:id="@+id/msg"
android:hint="@string/entertheip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text"
/>

<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Button1"
/>
<TextView android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/thetext"
android:visibility="invisible"
/>
</LinearLayout>


and corresponding java class is this



public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);

Button bu = (Button)findViewById(R.id.button1);
bu.setOnClickListener(new View.OnClickListener() {

private TextView tv = (TextView)findViewById(R.id.tv);

@Override
public void onClick(View v) {
// to view the ip in another page
try{
EditText et = (EditText)findViewById(R.id.msg);
String t = et.getText().toString();
tv.setText(t);

}catch(NullPointerException e){
e.printStackTrace();
}
}
});




}

}


But i am getting the Edit Text and Button only, the text is not showing in another page. Kindly help in this.


No comments:

Post a Comment