2

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

Siva K
  • 4,968
  • 14
  • 82
  • 161

1 Answers1

1

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
    }
}
bluefalcon
  • 4,225
  • 1
  • 32
  • 41