如何在旋转器中单击另一个项目时隐藏一个项目

时间:2016-04-05 06:51:42

标签: android textview hide spinner

这里的朋友是代码 当我点击亚马逊时,它正在出现,但当我点击快照时,亚马逊也在显示

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);
                    }

                }
            }
        });
    }

1 个答案:

答案 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

    }
});