|
程序如下:
Qstart.java/////////////////////
package dan.danart;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Qstart extends Activity{
private TextView shitsumon = null;
private TextView question = null;
private TextView choice = null;
private RadioGroup radiogroup = null;
private RadioButton radioButton1 = null;
private RadioButton radioButton2 = null;
private RadioButton radioButton3 = null;
private RadioButton radioButton4 = null;
private Button judge = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.qstart);
List<Integer> c = new ArrayList<Integer>();
c.add(R.id.radioButton1);
c.add(R.id.radioButton2);
c.add(R.id.radioButton3);
c.add(R.id.radioButton4);
Collections.shuffle(c,new Random());
question = (TextView)findViewById(R.id.question);
radiogroup = (RadioGroup)findViewById(R.id.radiogroup);
radioButton1 = (RadioButton)findViewById(c.get(0));
radioButton2 = (RadioButton)findViewById(c.get(1));
radioButton3 = (RadioButton)findViewById(c.get(2));
radioButton4 = (RadioButton)findViewById(c.get(3));
judge = (Button)findViewById(R.id.judge);
judge.setOnClickListener(new judgeListener());
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(radioButton1.getId() == checkedId){
Toast.makeText(Qstart.this,"1",Toast.LENGTH_SHORT).show();
}
else if(radioButton2.getId() == checkedId){
Toast.makeText(Qstart.this,"2",Toast.LENGTH_SHORT).show();
}
else if(radioButton3.getId() == checkedId){
Toast.makeText(Qstart.this,"3",Toast.LENGTH_SHORT).show();
}
else if(radioButton4.getId() == checkedId){
Toast.makeText(Qstart.this,"4",Toast.LENGTH_SHORT).show();
}
}
});
}
class judgeListener implements OnClickListener{
public void onClick(View v) {
Intent intent = new Intent();
String seikai = radioButton1.getText().toString();
intent.putExtra("two", seikai);
if(radioButton1.isChecked()){
String sentaku = radioButton1.getText().toString();
intent.putExtra("one",sentaku);
}if(radioButton2.isChecked()){
String sentaku = radioButton2.getText().toString();
intent.putExtra("one",sentaku);
}if(radioButton3.isChecked()){
String sentaku = radioButton3.getText().toString();
intent.putExtra("one",sentaku);
}if(radioButton4.isChecked()){
String sentaku = radioButton4.getText().toString();
intent.putExtra("one",sentaku);
}
intent.setClass(Qstart.this,answer.class);
Qstart.this.startActivity(intent);
Qstart.this.finish();
}
}
}
qstart.xml////////////////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/shitsumon"
android:id="@+id/shitsumon"
android:textColor="#0066ff"
android:textSize="25px">
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/question"
android:layout_below="@+id/shitsumon"
android:id="@+id/question">
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/choice"
android:layout_below="@+id/question"
android:id="@+id/choice"
android:textColor="#0066ff"
android:textSize="25px">
</TextView>
<RadioGroup android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
androidrientation="vertical"
android:layout_below="@+id/choice"
>
<RadioButton
android:text="@string/RadioButton1"
android:textColor="#000000"
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton
android:text="@string/RadioButton2"
android:textColor="#000000"
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton
android:text="@string/RadioButton3"
android:textColor="#000000"
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton
android:text="@string/RadioButton4"
android:textColor="#000000"
android:id="@+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
<Button
android:text="@string/judge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/radiogroup"
android:id="@+id/judge">
</Button>
</RelativeLayout>
执行模拟器后id的顺序虽然改变了,但是xml文件中的layout的位置指定显示1。2。3。4的顺序
怎么让界面上的按钮也改变顺序?
这个问题困扰我好多时间了
求大大们帮帮我吧 |
|