0

如果它是空的,我不想显示微调器下拉菜单。我试过了,但我没有得到请任何人都可以帮助我。

代码:

sp.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View arg0, MotionEvent event) {
        // TODO Auto-generated method stub
        //narray is the array. It's having the elements of spinner.
        if (event.getAction() == MotionEvent.ACTION_UP && narray.size() == 0) {
            sp.setPressed(false);
            sp.setSelected(false);
            sp.setAdapter(null);
        }
        return false;
    }       
});
4

2 回答 2

3

在你的代码中添加这个来检查数组大小是 <= 0

String[] b = {};

    spin = (Spinner) findViewById(R.id.spinner1);

            if (b.length <= 0) {
                spin.setClickable(false);
            }

试试这个代码微调器没有打开。

编辑:

像下面这样

    spin = (Spinner) findViewById(R.id.spinner1);

    spin.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        if (b.length <= 0) {
            spin.setClickable(false);
            Toast.makeText(StackoneActivity.this,
                    "spinner have no items", Toast.LENGTH_LONG).show();
        }
        return false;
    }
});
于 2013-01-22T06:36:45.157 回答
0

试试这个代码。

if(narray.size() >= 0)
sp.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View arg0, MotionEvent event) {
    // TODO Auto-generated method stub
    if (event.getAction() == MotionEvent.ACTION_UP ) {
        sp.setPressed(false);
        sp.setSelected(false);
        sp.setAdapter(null);
    }
    return false;
}       
});
于 2013-01-22T06:39:43.490 回答