任何人都可以告诉我如何检查是否选择了微调器我使用了它 代码,但它不起作用!
========================更新后===================== ===============
//=====================================================================================
//Duration Time + Spinner for Time Conditions + Retrieving time Part#1
CaseDurationH.clearChildFocus(null);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.feedbacktypelist, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
CaseDurationH.setAdapter(adapter);
CaseDurationH.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int i = CaseDurationH.getSelectedItemPosition();
strH = parent.getSelectedItem().toString();
try {
intH = Integer.parseInt(strH);
intHInMin=intH*60;
} catch (NumberFormatException nfe) {
}
if(i==2){
CaseDurationM.setEnabled(false);
}
if(strH.equals("hr0"))
{
CaseDurationM.setEnabled(true);
}
if(strH.equals("hr1"))
{
CaseDurationM.setEnabled(true);
}
if(strH.equals("hr2"))
{
CaseDurationM.setEnabled(false);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
//=====================================================================================
// Duration Time Part#2
CaseDurationM.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int i = CaseDurationM.getSelectedItemPosition();
strM = parent.getSelectedItem().toString();
try {
intM = Integer.parseInt(strM);
} catch (NumberFormatException nfe) {
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
//=====================================================================================
// For Disabling The Buttons
void updateButtonState() {
if( CheckSpinner(CaseDurationH , CaseDurationM) && checkEditText2(CaseName) && checkEditText2(CaseAge) && CheckRButtons(RBMale, RBFemale) ) {
Nextb.setEnabled(true);}
else {Nextb.setEnabled(false);}
}
//=============================================================================
// For Spinner
private boolean CheckSpinner(Spinner caseDurationH2, Spinner caseDurationM2) {
// TODO Auto-generated method stub
boolean CheckingSpinners= false;
if (caseDurationH2.isSelected() && caseDurationM2.isSelected() )
CheckingSpinners= true;
return CheckingSpinners;
}
=============================================== ================================
问题:
答案 0 :(得分:0)
为微调器setOnItemSelectedListener
添加侦听器并在OnNothingSelected(...)
请参阅此示例http://saigeethamn.blogspot.in/2010/05/spinner-view-android-beginner-dev.html