在对话框内的列表视图上执行 onclick 操作

发布于 2025-01-08 14:06:38 字数 1079 浏览 1 评论 0原文

在我的应用程序中,当我单击显示带有列表视图的对话框的按钮时。项目列表从数组列表中显示。以下是我的代码的一部分

private void album_list_box() 
    {
        Dialog dialog = new Dialog(Nearme_Image_DetailView.this);
        AlertDialog.Builder builder = new AlertDialog.Builder(Nearme_Image_DetailView.this);
        builder.setTitle("Select the Album Name");

        ListView modeList = new ListView(this);
        for(int i =0; i< Get_album_name_array.size(); i++)
        {
            stringArray = Get_album_name_array.get(i);
            HashMap<String, Object> map = new HashMap<String, Object>(); 
            map.put("fname", stringArray);
            listItem.add(map);
        }
        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,android.R.layout.simple_list_item_1,new String[] {"fname"}, new int[] {android.R.id.text1});   
        modeList.setAdapter(listItemAdapter);

        builder.setView(modeList);
        dialog = builder.create();
        dialog.show();
    }

这里我正在获取警报框和项目列表,当我单击时我可以获得位置。

但是当单击列表时我想关闭对话框并且我想启动一个异步任务,该怎么做......

in my app when i click a button showing a dialog box with listview. The list of items are been shown from an array list. Following is the bit of my code

private void album_list_box() 
    {
        Dialog dialog = new Dialog(Nearme_Image_DetailView.this);
        AlertDialog.Builder builder = new AlertDialog.Builder(Nearme_Image_DetailView.this);
        builder.setTitle("Select the Album Name");

        ListView modeList = new ListView(this);
        for(int i =0; i< Get_album_name_array.size(); i++)
        {
            stringArray = Get_album_name_array.get(i);
            HashMap<String, Object> map = new HashMap<String, Object>(); 
            map.put("fname", stringArray);
            listItem.add(map);
        }
        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,android.R.layout.simple_list_item_1,new String[] {"fname"}, new int[] {android.R.id.text1});   
        modeList.setAdapter(listItemAdapter);

        builder.setView(modeList);
        dialog = builder.create();
        dialog.show();
    }

Here i am a getting the alertbox and list of items, when i click i am able to get the position.

But when the list is clicked i want to close the dialog and i want to start an async Task, how to do this......

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2025-01-15 14:06:38

dialog声明为类成员,为ListView设置点击监听器

lv.setOnItemClickListener(new OnItemClickListener() {    
    public void onItemClick(AdapterView<?> parent,View view,int position,long id) {
        //your code
        mdialog.cancel(); // close the dialog box
        asynctask = new ASyncTask().execute(); // start a aynctask of your choice
    }
}

Declare the dialog as class member, set up the click listener for the ListView

lv.setOnItemClickListener(new OnItemClickListener() {    
    public void onItemClick(AdapterView<?> parent,View view,int position,long id) {
        //your code
        mdialog.cancel(); // close the dialog box
        asynctask = new ASyncTask().execute(); // start a aynctask of your choice
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文