public class Sample extends Activity {
Spinner `sp`;
TextView tv,tv1,tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.textView1);
tv1=(TextView)findViewById(R.id.textView2);`enter code here`
tv2=(TextView)findViewById(R.id.textView3);
String items[]={"amazon","flipkart","snapdeal"};
ArrayAdapter aa=new ArrayAdapter(Sample.this,android.R.layout.simple_spinner_dropdown_item,items);
sp.setAdapter(aa);
sp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position)
{
case 0:
{
if(tv.getVisibility() == View.VISIBLE)
tv.setVisibility(View.GONE);
else
tv.setVisibility(View.VISIBLE);
}
case 1:
{
if(tv1.getVisibility() == View.VISIBLE)
tv1.setVisibility(View.GONE);
else
tv1.setVisibility(View.VISIBLE);
}
}
}
});
}
答案 0 :(得分:0)
另一种解决方案......拥有单一textView并更新此textView的文本。
String textSelected = "Select from the drop down";
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
textSelected = parent.getItemAtPosition(pos).toString();
textView.setText(textSelected);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});