I have made an android app named Yash on AIDE. It has an edittext,textview & a button. It is designed to first take input through the edittext then when we press the button, it should display the edittext text on the textview. It starts & takes the input but as I press the button, it hangs & shows:"Unfortunately Yash has stopped."
Xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/oButton"/>
/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Go!"
android:onClick="bc"
android:id="@+id/goButton"></Button>
</LinearLayout>
Java:
package com.mycompany.myapp4;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Toast;
import android.widget.EditText;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void bc(View view){
EditText t = (EditText) findViewById(R.id.editText);
String s = t.getText().toString();
TextView textView = (TextView) findViewById(R.id.oButton);
textView.setText(s);
}
}