package a.b.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
public class HelloWorld2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*button*/
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener ( new View.OnClickListener()
{
public void onClick(View v) {
EditText edt= (EditText)HelloWorld2Activity.this.findViewById(R.id.edt);
TextView txt= (TextView)HelloWorld2Activity.this.findViewById(R.id.txt);
txt.setText(getString(R.string.msg_dialog)+edt.getText());
}
});//end of btn.setOnClickListener
}
}
=============main.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:orientation="vertical" >
<TextView
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go" />
<EditText
android:id="@+id/edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberPassword" >
<requestFocus />
</EditText>
</LinearLayout>
==========strings.xml================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloWorld2!</string>
<string name="app_name">Button</string>
<string name="tit_dialog">提示</string>
<string name="msg_dialog">你好,中国</string>
<string name="ok_dialog">确定</string>
<string name="go">浏览</string>
</resources>