This is my code, what’s the matter?
Operation result is “has stopped unexpectedly”.
It can go through when remove the OnClickListener,that is say, that button to click on the binding is wrong?
gao.java
package cn.gao;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class gao<hellotwo> extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText edt=(EditText)gao.this.findViewById(R.id.edt);
TextView txt=(TextView)gao.this.findViewById(R.id.txt);
txt.setText(getString(R.string.msg_dialog)+edt.getText());
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText id="@+id/edt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<EditText id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<Button id="@+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go">
<requestFocus />
</Button>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">hello android</string>
<string name="app_name">hellotwo</string>
<string name="tit_dialog">提示</string>
<string name="msg_dialog">你好,中国</string>
<string name="ok_dialog">确定</string>
<string name="go">浏览</string>
</resources>
Tested Code below,
activity_main.xml:
MainActivity.java:
string.xml:
Output:

Hope it will help you. 🙂