I have a EditText and a Button in my activity xml. What i wanted to do is that on clicking the button the text from the EditText should get displayed in a TextView above the EditText.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
<EditText
android:id="@+id/edit_message"
android:hint="@string/hint_message"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:id="@+id/button_send"
android:text="@string/button_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="sendMessage"/>
and this is my sendMessage()
public void sendMessage(View view){
EditText editText=(EditText)findViewById(R.id.edit_message);
String message=editText.getText().toString();
LinearLayout layout=(LinearLayout)findViewById(R.id.layout01);
TextView text=new TextView(this);
text.setText(message);
layout.addView(text);
}
When i click the button, nothing happens. Nothing at all. Any idea why this is not working? I'm pretty new to Android development.