我需要能够在“Hello world!”的两个文本值之间切换。和“你好!!!”。我知道这将非常简单,但是由于我对编程很陌生,所以请耐心等待。提前致谢。
package edu.purdue.cnit355_lab1;
public class MainActivity extends Activity {
private Button HelloButton;
private TextView Message;
private OnClickListener HelloButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
Message.setText("Hello!!!");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HelloButton = (Button) findViewById(R.id.HelloButton);
Message = (TextView) findViewById(R.id.MessageText);
HelloButton.setOnClickListener(HelloButtonListener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我的layout.main.xml
:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/HelloButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_button_label"
/>
<TextView
android:id="@+id/MessageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
/>
</RelativeLayout>
我的strings.xml
:
<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">Hello Button</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="hello_button_label">Say "Hello!".</string>