title: How to capture List Dialog result - Android
body: <p>I am new to Android. I am stuck, need help.  </p>
  
  <p>I have a List as my <code>Activity</code>. <code>OnItemLongClickListener</code> for any element of a List, I am displaying a Dialog with Custom List (Red, Green, Blue) &amp; on the selection of any of the items (Red, Green, Blue) I need to change the back color of the selected item (on which the event raised the Dialog) of a List (main activity).  </p>
  
  <p>The dialog box pops, but I am stuck how to get the selected item (of Dialog). Below is my code.  </p>
  
  <pre><code> public class SimpleList extends ListActivity 
   {  
    String[] contactNames = {"Name 1", "Name 2", "Name 3", "Name 4", "Name 5", "Name 6"};  
  
   ArrayAdapter&lt;String&gt; contactAdpater;  
   String itemSelected;  
   String choosenColor;  
   private final Context context = this;  
  
   public void onCreate(Bundle savedInstanceState)   
  {  
     super.onCreate(savedInstanceState);  
     ArrayList&lt;String&gt; myContactList = new ArrayList&lt;String&gt;(Arrays.asList(contactNames));  
  
    OnItemLongClickListener itemChangeColorListener = new OnItemLongClickListener() {  
    @Override  
    public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View arg1, int position, long arg3) {  
       itemSelected = parent.getItemAtPosition(position).toString();  
  AlertDialog.Builder builder = new AlertDialog.Builder(context);  
  final String[] colorNames = {"Red","Green","Blue"};  
  builder.setTitle("Pick a Colour!")    
         .setItems(colorNames, new DialogInterface.OnClickListener()   
                {  
              @Override  
         public void onClick(DialogInterface dialog, int which)   
                   {  
            choosenColor = colorNames[which];  
                      //Toast.makeText(getApplicationContext(), colorNames[which], Toast.LENGTH_SHORT).show(); &lt;&lt;-- its working fine here  
  
                     //I am not able to access parent here... I want to perform,  
                   **//parent[position].setBackgroundColor(Color.RED); in case Red is selected from Dialog**  
  
        }  
           });  
               builder.show();      
          return false;  
      }  
   };  
   contactAdpater = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,
              myContactList);  
   setListAdapter(contactAdpater);  
   getListView().setOnItemLongClickListener(itemChangeColorListener);   
    }  
   }  
  </code></pre>