//Test1Activity
package csie.stut.edu.tw;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Button;
import android.widget.RadioButton;
public class Test1Activity extends Activity {
/** Called when the activity is first created. */
CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
RadioButton radio1, radio2, radio3;
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("選擇字型外觀!");
setContentView(R.layout.main);
find_and_modify_text_view();
}
private void find_and_modify_text_view() {
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
radio1 = (RadioButton) findViewById(R.id.radio1);
radio2 = (RadioButton) findViewById(R.id.radio2);
radio3 = (RadioButton) findViewById(R.id.radio3);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(button1Listener);
}
private Button.OnClickListener button1Listener = new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String r = "";
if (checkBox1.isChecked())
r = r + " " + (String) checkBox1.getText();
if (checkBox2.isChecked())
r = r + " " + (String) checkBox2.getText();
if (checkBox3.isChecked())
r = r + " " + (String) checkBox3.getText();
if (checkBox4.isChecked())
r = r + " " + (String) checkBox4.getText();
if (radio1.isChecked())
r = r + " " + (String) radio1.getText();
if (radio2.isChecked())
r = r + " " + (String) radio2.getText();
if (radio3.isChecked())
r = r + " " + (String) radio3.getText();
setTitle("你選擇的是:" + r);
}
};
}
===================================================================
//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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="字型外觀"
android:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="正常" >
</CheckBox>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Serif"
android:typeface="serif" >
</CheckBox>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="粗體"
android:textStyle="bold" >
</CheckBox>
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斜體"
android:textStyle="italic" >
</CheckBox>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你喜歡的手機"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Android" >
</RadioButton>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="iOS" >
</RadioButton>
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Windows Phone" >
</RadioButton>
</RadioGroup>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="選一個!" >
</Button>
</LinearLayout>
關於 小巴 | ||
出現在網路上的小小部落客,白天是隱身在某某科大的學生,一到晚上就會現身在傳說中的秘密工作室。對於3C和網路有高度的熱情,偶爾研究APP、寫寫程式,是個最近很忙碌的學生。 | ||
沒有留言:
張貼留言
請提供您寶貴的意見