菜鸟请教高手关于XML的一些问题
fty 2011-02-14 10:48:08 是这样的 其实问题也不严重
我建了一个ACTIVITY和对应的MAIN.XML但是不知道为什么 每次第一次打开ECLIPSE的时候,都提示MAIN.XML中有错误,我检查了以后觉得没错误,就把它提示错误的代码删除了,重新写一个一样的,错误消失了,但是再打开ECLIPSE的时候错误又出现了,虽然不是什么要紧的程序 但是看着挺闹心的 大家帮忙分析下原因
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="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" />
<RadioGroup android:id="@+id/genderGroup"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/femaleButton"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/female" />
<RadioButton android:id="@+id/maleButton"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="@string/male" />
</RadioGroup>
<CheckBox android:id="@+id/swim" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="@string/swim" />
<CheckBox android:id="@+id/run" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="@string/run" />
<CheckBox android:id="@+id/read" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="@string/read" />
</LinearLayout>
错误提示为:Multiple annotations found at this line:
- error: Error parsing XML: duplicate attribute
- Attribute "android:layout_height" was already specified for element
"RadioButton".
package fty.activity_07;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class radioTest extends Activity {
/** Called when the activity is first created. */
private RadioGroup genderGroup = null;
private RadioButton femaleButton = null;
private RadioButton maleButton = null;
private CheckBox swimBox = null;
private CheckBox runBox = null;
private CheckBox readBox = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
genderGroup = (RadioGroup) findViewById(R.id.genderGroup);
femaleButton = (RadioButton) findViewById(R.id.femaleButton);
maleButton = (RadioButton) findViewById(R.id.maleButton);
swimBox = (CheckBox) findViewById(R.id.swim);
runBox = (CheckBox) findViewById(R.id.run);
readBox = (CheckBox) findViewById(R.id.read);
// 当点击单选按钮组中任意一个选项时,都会触发监听器,在监听器内部进行判断
genderGroup
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == femaleButton.getId()){Toast.makeText(radioTest.this, "female", Toast.LENGTH_SHORT).show();}
else if(checkedId == maleButton.getId()){Toast.makeText(radioTest.this, "male", Toast.LENGTH_LONG).show();}
}
});
swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){Toast.makeText(radioTest.this, "swimBox is Checked", Toast.LENGTH_SHORT).show();}
else{Toast.makeText(radioTest.this, "swimBox is Unchecked", Toast.LENGTH_SHORT).show();}
}
});
runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){Toast.makeText(radioTest.this, "runBox is Checked", Toast.LENGTH_SHORT).show();}
else{Toast.makeText(radioTest.this, "runBox is Unchecked", Toast.LENGTH_SHORT).show();}
}
});
readBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){Toast.makeText(radioTest.this, "readBox is Checked", Toast.LENGTH_SHORT).show();}
else{Toast.makeText(radioTest.this, "readBox is Unchecked", Toast.LENGTH_SHORT).show();}
}
});
}
}