我的微调器未调用 OnItemSelectedListener()
您好,我有一个微调器,我使用“visibility = gone”属性隐藏了它。我使用 spinner.performclick() 调用微调器列表,这工作正常,除了在微调器列表中选择项目时,我的 onselect 侦听器永远不会被调用。请帮忙:)
抛出的唯一目录警告是“窗口已经聚焦,忽略焦点增益”
catagorySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
CashDB cdb = new CashDB(getBaseContext());
cdb.open();
Cursor c = cdb.FetchCatagory(id);
startManagingCursor(c);
c.moveToFirst();
String newCatagoryName = c.getString(c.getColumnIndexOrThrow(CashDB.CATAGORY_NAME));
c.close();
areYouSureDialog("Are You Sure?", "Are you sure you want to delete the catagory " +'"'
+ catagoryName + '"'+ " and move all of the transactions to " +'"'
+ newCatagoryName + '"' + " ?",
catagoryIcon, catagoryName,newCatagoryName, DELETE_CATAGORY_MOVE, catagoryId);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
Hi i have a spinner that i have hidden using visibility = gone atribute. i call the spinner list using spinner.performclick() , this works fine except for that when selecting an item in the spinner list my onselect listener is never being called. please help:)
the only catlog warning being thrown is "window already focused, ignoring focus gain"
catagorySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
CashDB cdb = new CashDB(getBaseContext());
cdb.open();
Cursor c = cdb.FetchCatagory(id);
startManagingCursor(c);
c.moveToFirst();
String newCatagoryName = c.getString(c.getColumnIndexOrThrow(CashDB.CATAGORY_NAME));
c.close();
areYouSureDialog("Are You Sure?", "Are you sure you want to delete the catagory " +'"'
+ catagoryName + '"'+ " and move all of the transactions to " +'"'
+ newCatagoryName + '"' + " ?",
catagoryIcon, catagoryName,newCatagoryName, DELETE_CATAGORY_MOVE, catagoryId);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将微调器的可见性保留为 INVISIBLE,但设置 android:layout_width="0dp" 和 android:layout_height="0dp"
这样,微调器实际上不在 UI 中,直到您调用 PerformClick(),然后它就会出现,用户做出选择,微调器会折叠回 0x0 ...,然后您会收到 onItemSelected 事件。
Leave the visibility for the spinner at INVISIBLE, but set the android:layout_width="0dp" and android:layout_height="0dp"
That way, the spinner is effectively not in the UI until you call performClick(), then it appears, user makes the choice and the spinner collapses back to 0x0 ... and you get the onItemSelected event.