如果它是空的,我不想显示微调器下拉列表。我试过但是我没有得到,请任何人都可以帮助我。
代码:
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;
}
});
答案 0 :(得分: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;
}
});
答案 1 :(得分: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;
}
});