public class Activity_demo1 extends Activity {
EditText etUsername;
RadioGroup rgSubject;
CheckBox cbSchool, cbInternet, cbFriend;
Spinner spChose;
Button btnSure;
RadioButton rbAndroid, rbIos;
String subStr, cbschool, cbinternet, cbfriend, username, chose, ckchose;
ArrayAdapter<String> adapter;
static final String TAG = "Activity_demo1";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_demo1);
Log.i(TAG, "onCreate");
// 初始化
etUsername = (EditText) findViewById(R.id.etUsername);
rgSubject = (RadioGroup) findViewById(R.id.rgSubject);
cbSchool = (CheckBox) findViewById(R.id.cbSchool);
cbInternet = (CheckBox) findViewById(R.id.cbInterner);
cbFriend = (CheckBox) findViewById(R.id.cbFriend);
spChose = (Spinner) findViewById(R.id.spChose);
btnSure = (Button) findViewById(R.id.btnSure);
rbAndroid = (RadioButton) findViewById(R.id.rbAndroid);
rbIos = (RadioButton) findViewById(R.id.rbIos);
// 选择课程
rgSubject
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if (arg1 == R.id.rbAndroid)
subStr = rbAndroid.getText().toString();
else
subStr = rbIos.getText().toString();
}
});
// 适配器
final String[] price = { "5000", "6000", "7000", "8000", "10000" };
adapter = new ArrayAdapter<String>(Activity_demo1.this,
android.R.layout.simple_spinner_item, price);
spChose.setAdapter(adapter);
// 期望薪金
spChose.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
chose = price[arg2];
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void go(View view) {
List<String> list = new ArrayList<String>();
// 信息来源
if (cbSchool.isChecked())
list.add(cbSchool.getText().toString());
else
list.remove(cbSchool.getText().toString());
if (cbFriend.isChecked())
list.add(cbFriend.getText().toString());
else
list.remove(cbFriend.getText().toString());
if (cbInternet.isChecked())
list.add(cbInternet.getText().toString());
else
list.remove(cbInternet.getText().toString());
// 姓名
username = etUsername.getText().toString();
}
1.onclick中能些什么呢?????
2.姓名和信息来源放在onClick()中就能获取值,在onCreate()就不能????
3.相反,选择课程、薪金、适配器放在onClick()中就不能获得值,在onCreate()就能?????
求解答,万分感谢
EditText etUsername;
RadioGroup rgSubject;
CheckBox cbSchool, cbInternet, cbFriend;
Spinner spChose;
Button btnSure;
RadioButton rbAndroid, rbIos;
String subStr, cbschool, cbinternet, cbfriend, username, chose, ckchose;
ArrayAdapter<String> adapter;
static final String TAG = "Activity_demo1";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_demo1);
Log.i(TAG, "onCreate");
// 初始化
etUsername = (EditText) findViewById(R.id.etUsername);
rgSubject = (RadioGroup) findViewById(R.id.rgSubject);
cbSchool = (CheckBox) findViewById(R.id.cbSchool);
cbInternet = (CheckBox) findViewById(R.id.cbInterner);
cbFriend = (CheckBox) findViewById(R.id.cbFriend);
spChose = (Spinner) findViewById(R.id.spChose);
btnSure = (Button) findViewById(R.id.btnSure);
rbAndroid = (RadioButton) findViewById(R.id.rbAndroid);
rbIos = (RadioButton) findViewById(R.id.rbIos);
// 选择课程
rgSubject
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
if (arg1 == R.id.rbAndroid)
subStr = rbAndroid.getText().toString();
else
subStr = rbIos.getText().toString();
}
});
// 适配器
final String[] price = { "5000", "6000", "7000", "8000", "10000" };
adapter = new ArrayAdapter<String>(Activity_demo1.this,
android.R.layout.simple_spinner_item, price);
spChose.setAdapter(adapter);
// 期望薪金
spChose.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
chose = price[arg2];
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void go(View view) {
List<String> list = new ArrayList<String>();
// 信息来源
if (cbSchool.isChecked())
list.add(cbSchool.getText().toString());
else
list.remove(cbSchool.getText().toString());
if (cbFriend.isChecked())
list.add(cbFriend.getText().toString());
else
list.remove(cbFriend.getText().toString());
if (cbInternet.isChecked())
list.add(cbInternet.getText().toString());
else
list.remove(cbInternet.getText().toString());
// 姓名
username = etUsername.getText().toString();
}
1.onclick中能些什么呢?????
2.姓名和信息来源放在onClick()中就能获取值,在onCreate()就不能????
3.相反,选择课程、薪金、适配器放在onClick()中就不能获得值,在onCreate()就能?????
求解答,万分感谢