我正在开发我的第一个android应用程序,但面临着一个难题。在我应用程序中,有一个页面使用listview显示所有sqlite数据库记录。我希望微调可以弹出由用户长时间点击列表视图,但它强制关闭。
private ListView.OnItemLongClickListener modItem = new ListView.OnItemLongClickListener()
public boolean onItemLongClick(AdapterView<?> arg0, View v,int index, long arg3)
{
//I don't know what should I put in the parameter of the spinner constructor
sp_choice = new Spinner(<???>);
//Same problem that I don't know what should I put in <???>
ArrayAdapter<String> adt = new ArrayAdapter<String>(<???>,android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.choice_array));
adt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp_choice.setAdapter(adt);
return true;
}
};发布于 2013-06-16 13:03:34
我认为最好是使用弹出菜单或对话框来进行弹出选择,而不是在运行时使用微调器。
对于对话框,它看起来像这样:
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
AlertDialog.Builder choiceDialogBuilder = new Builder(YourActivity.this);
choiceDialogBuilder.setSingleChoiceItems(R.array.app_array, 0, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(YourActivity.this,
getResources().getStringArray(R.array.app_array)[which],
Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
choiceDialogBuilder.create().show();
return true;
}
};发布于 2013-06-16 12:58:16
对不起,我听不懂你的问题。
让我看看我有没有弄错..。当长时间单击列表视图的一个项目时,你想要一个带有选项列表或注册表的对话框,还是你想从头开始实例化一个微调器?
如果你想打开一个选项列表,我会推荐一些ListDialog。你可以根据下面的代码来实例化它:
Builder dialog = new AlertDialog.Builder(getSherlockActivity());
dialog.setTitle(<TITLE>)
.setItems(<YOUR_LIST>, <Click Listener>)
.create().show();如果不是,
你想从代码中创建一个微调控件吗?您不是在使用xml资源吗?要从代码实例化微调器,必须在上传递上下文,以及布局参数和微调器的模式(Dropdown或Dialog),并在适配器的上传递带有元素的字符串列表...不过,对于初学者来说,这似乎是一项艰巨的工作。如果没有必要,我建议您使用xml资源...
如果我没听懂,请澄清你的问题...
欢迎光临!
https://stackoverflow.com/questions/17130233
复制相似问题