我制作一个微调器,当我从微调器中选择一个特定的项目然后编辑文本时,我可以看到其他明智的看不见。这一切都很好 但是当用户选择特定项目时我想要一个问题然后编辑文本的值存储在变量中,否则sppiner项值存储意味着如果用户选择“OTH-Other”然后在spinnerSelectedID中编辑文本值存储,否则移动到else。 我的elese部分工作得很好,但如果部分我无法将编辑文本值存储在spinnerSelectedID varible中。
ArrayList<String> faulttypespinner = new ArrayList<String>();
faulttypespinner.add("XL-Cross Level");
faulttypespinner.add("AL-Alignment");
faulttypespinner.add("UN-Unevenness");
faulttypespinner.add("XL-Cross Level");
faulttypespinner.add("AL-Alignment");
faulttypespinner.add("UN-Unevenness");
faulttypespinner.add("BD-Ballast Deficiency");
faulttypespinner.add("SE-Super elevation on curve");
faulttypespinner.add("LP-Loose Packing");
faulttypespinner.add("LJ-Low Joint");
faulttypespinner.add("BA-Bridge");
faulttypespinner.add("LC-Level Crossing");
faulttypespinner.add("LJ-Low Joint");
faulttypespinner.add("P and C-Point n Xing");
faulttypespinner.add("OTH-Other");
faulttypespinner.add("SEJ-SEJ");
faulttypespinner.add("WEED-Weed on Cess");
ArrayAdapter<String> faultadapter = new ArrayAdapter<String>
(mConetxt,android.R.layout.simple_spinner_item, faulttypespinner);
faultadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mspinner.setAdapter(faultadapter);
mspinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Log.d("TESTING", parent.getItemAtPosition(pos).toString());
if(parent.getItemAtPosition(pos).toString().equals("OTH-Other")) {
otherdefect.setVisibility(View.VISIBLE);
text = otherdefect.getText().toString();
spinnerSelectedID = String.valueOf(mspinner.getSelectedItem());
spinnerSelectedID = (otherdefect.getText().toString());
}
else
{
otherdefect.setVisibility(View.GONE);
spinnerSelectedID = String.valueOf(mspinner.getSelectedItem());
}
}