本文介绍了设置片段类中微调器的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有2个微调器的片段类,一个微调器有3个值,即零售商,管理员和订阅者,当点击零售商选项时,第二个微调器必须是可见的,当点击其他2个选项时,第二个微调器必须是不可见的。



我使用的代码如下

这是片段的onResume方法中的第一个微调器。

 logAs =(Spinner)getActivity()。findViewById(R.id.spinner5); 
列表list = new ArrayList();
list.add( Subscriber);
list.add( 零售商);
list.add( 管理员);
ArrayAdapter dataAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_spinner_item,list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
logAs.setAdapter(dataAdapter);
logAs.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener(){
@ Override
public void onItemSelected(AdapterView<?> parent,View view, int position, long id){
switch (位置){
case 0 :
// chooseRetailerDetails();
// choodeRetailer.setVisibility(View.INVISIBLE);

break ;
case 1 :
chooseRetailerDetails();

// choodeRetailer.setVisibility(View.VISIBLE);
break ;
case 3 :
/ / choodeRetailer.setEnabled(false);

break ;
}
}
});





现在在case语句中我尝试设置第二个微调器的可见性我得到一个空指针异常。

解决方案

I have a fragment class with 2 spinners, one spinner has 3 values namely retailer, admin and subscriber, when the retailer option is clicked the 2nd spinner must be visible and when the other 2 options are clicked the 2nd spinner must be invisible.

the code i used is as follows
this is the first spinner in onResume method of the fragment.

logAs = (Spinner) getActivity().findViewById(R.id.spinner5);
        List list = new ArrayList();
        list.add("Subscriber");
        list.add("Retailer");
        list.add("Administrator");
        ArrayAdapter dataAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        logAs.setAdapter(dataAdapter);
        logAs.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                       //chooseRetailerDetails();
                       // choodeRetailer.setVisibility(View.INVISIBLE);

                        break;
                    case 1:
                        chooseRetailerDetails();

                        //choodeRetailer.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        //choodeRetailer.setEnabled(false);

                        break;
                }
            }
        });



now in the case statement when i try to set the visibility of the second spinner i get a null pointer exception.

解决方案


这篇关于设置片段类中微调器的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:39