我有一个带有一些选项的微调器,我想在选择特定的“其他”选项时更改文本框的可见性,我该怎么做?
this.arraySpinner = new String[] {"Mobile", "Gaming", "Media Features", "Medical", "Sports And Nutrition","Security","Space","Other"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, arraySpinner);
categories.setAdapter(adapter);
答案 0 :(得分:0)
你可以在微调器中实现OnItemSelected并做你想做的事情。
categories.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if(arraySpinner!=null && arraySpinner[position].equalIgnoreCase("Other")){
// your code here
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
答案 1 :(得分:0)
试试这个:
.................
........................
this.arraySpinner = new String[] {"Mobile", "Gaming", "Media Features", "Medical", "Sports And Nutrition","Security","Space","Other"};
// Views
categories= (Spinner) findViewById(R.id.spinner);
textView = (TextView) findViewById(R.id.textView);
// Adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraySpinner);
categories.setAdapter(adapter);
// Set onItemSelected listener to spinner
categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
TextView spinnerText = (TextView) view;
// Checking weather selected item is "Other" or not
if (spinnerText.getText().equals("Other"))
{
// Hide TextView
textView.setVisibility(View.INVISIBLE); // or View.GONE
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
.............
...................
希望这会有所帮助