在对话框内的listview上执行onclick操作

时间:2012-02-24 10:56:50

标签: android listview dialog android-asynctask

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

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();
    }

我在这里获取提示框和项目列表,当我点击我能够获得该位置时。

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

1 个答案:

答案 0 :(得分:1)

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
    }
}