80,472
社区成员




private boolean checkForm(int layoutId) {
//RelativeLayout layout = (RelativeLayout) getLayoutInflater().inflate(layoutId, null);
RelativeLayout layout = (RelativeLayout)LayoutInflater.from(this).inflate(layoutId, null);
layout = (RelativeLayout)findViewById(R.id.widget36);
boolean flag = true;
for (int i = 0; flag && i < layout.getChildCount(); i++) {
View v = layout.getChildAt(i);
// Log.v("ID",v.getClass().getName().toString() + "," + v.getId());
flag = checkView(v);
}
return flag;
}
private boolean checkView(View v) {
boolean flag = true;
//! 为什么所有的控件都取不到值 !!!
Log.v("check", v.getClass().getName().toString() + "," + v.getId());
if ((v instanceof ImageView) || (v instanceof TextView)) {
return true;
} else if (v instanceof EditText) {
// Log.v("test", v.getId() + "EditText="
// +((EditText)v).getText().toString());
// if (((EditText) v).getText().toString().equals("")) {
// Log.v("return", v.getClass().toString());
// return false;
// }
EditText e = (EditText) findViewById(v.getId());
Log.v("test", "editText=" + e.getText().toString());
return true;
} else if (v instanceof Spinner) {
// Log.v("return",(((Spinner)v).getSelectedItemId() ==
// AdapterView.INVALID_ROW_ID) + "");
if (((Spinner) v).getSelectedItem() == null) {
Log.v("return", v.getClass().toString());
// ! SO DOES Spinner!!! CANNOT getValue!!
// return false;
return true;
}
} else if (v instanceof RadioGroup) {
if (((RadioGroup) v).getCheckedRadioButtonId() == -1) {
// Log.v("return", v.getClass().toString() + "," +
// ((RadioGroup)v).getCheckedRadioButtonId());
// ? return false;
return true;
}
} else if (v instanceof ViewGroup) {
Log.v("Recurve", v.getClass().toString());
for (int i = 0; flag && i < ((ViewGroup) v).getChildCount(); i++) {
View vx = ((ViewGroup) v).getChildAt(i);
flag = checkView(vx);
}
return flag;
}
Log.v("return2", v.getClass().toString());
return true;
}
private boolean checkForm(int layoutId) {
//你的代码里用这个就可以了
RelativeLayout layout = (RelativeLayout)findViewById(layoutId);
RelativeLayout loginLayout =(RelativeLayout)findViewById(R.id.relativeLayout1); //(RelativeLayout) getLayoutInflater().inflate(R.layout.oneactivity, null);
for (int i = 0; i < loginLayout.getChildCount(); i++) {
View v1=loginLayout.getChildAt(i);
if(v1 instanceof EditText ){
Log.v("check", v1.getClass().getName().toString() + "," + v1.getId());
EditText e = (EditText)findViewById(v1.getId());
Log.v("test", "editText=" + e.getText().toString());
}
}