title: How do i add popup window in listview when onclick of item using android studio?
body: <p>I am implementing listview with multiple widgets like textview, checkbox, imageview and spinner in one row of listview. Now i want to show pop up window when i click on any row of listview. How do i do ? 
  following is my code, can you suggest me?</p>
  
  <p>//MainActivity.java</p>
  
  <p>public class MainActivity extends AppCompatActivity {</p>
  
  <pre><code>private ListView mListView;
  
  private int[] startImages = new int[]{
          R.drawable.areaname,R.drawable.email,R.drawable.user};
  
  private String[] mColorNames = new String[]{
          "1", "2", "3"};
  
  private List&lt;ListModel&gt; listModelList = new ArrayList&lt;&gt;();
  private String TAG = "Lokesh";
  
  private PopupWindow popupWindow;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mListView = (ListView) findViewById(R.id.listView);
      loadListWithImages();
      final ListAdapter adapter = new ListAdapter(listModelList,this);
      mListView.setAdapter(adapter);
      Log.d(TAG, "onCreate: list"+listModelList.size());
  
      mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              // String s = mListView.getItemAtPosition(position).toString();
             // String s = mListView.getSelectedItem().toString();
  
  
          }
      });
  }
  
  
  private void loadListWithImages() {
      for (int i = 0; i &lt; startImages.length; i++) {
          ListModel listModel = new ListModel();
          listModel.setCount(0);
          listModel.setImage(startImages[i]);
          listModel.setName(mColorNames[i]);
          listModelList.add(listModel);
      }
  }
  
  //pop up window
  
  private void initiatePopupWindow() {
      try {
          // We need to get the instance of the LayoutInflater
          LayoutInflater inflater = (LayoutInflater) MainActivity.this
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View layout = inflater.inflate(R.layout.screen_popup,
                  (ViewGroup) findViewById(R.id.popup_element));
          popupWindow = new PopupWindow(layout, 300, 370, true);
          popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
  
       //   btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
      //    btnClosePopup.setOnClickListener(cancel_button_click_listener);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  private View.OnClickListener cancel_button_click_listener = new View.OnClickListener() {
      public void onClick(View v) {
          popupWindow.dismiss();
  
      }
  };
  </code></pre>
  
  <p>}</p>
  
  <p>//ListAdapter.java</p>
  
  <p>public class ListAdapter extends BaseAdapter implements android.widget.ListAdapter</p>
  
  <pre><code>{
  
      private List&lt;ListModel&gt; listModelList;
      private Context mContext;
      private LayoutInflater inflater;
      private String TAG = "LokeshSA";
      private String[] mColorNames = new String[]{
              "1", "2", "3" };
      private String[] listitems=new String[]{"One", "Two", "Three"};
  
  public ListAdapter(List&lt;ListModel&gt; listModelList, Context mContext) {
      this.listModelList = listModelList;
      this.mContext = mContext;
      inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
      @Override
      public int getCount() {
      return listModelList.size();
  
  }
  
      @Override
      public Object getItem(int position) {
      return listModelList.get(position);
  }
  
      @Override
      public long getItemId(int position) {
      return position;
  }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
      //  ViewHolder holder = null;
      final ViewHolder holder;
  
      if (convertView == null) {
          convertView = inflater.inflate(R.layout.single_list_items, null);
          holder = new ViewHolder();
  
          //checkbox
  
          holder.checkbox = (CheckBox) convertView.findViewById(R.id.listview_cb);
          holder.checkbox
                  .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView,
                                                   boolean isChecked) {
                          ListModel element = (ListModel) holder.checkbox
                                  .getTag();
                          element.setSelected(buttonView.isChecked());
  
                      }
                  });
          convertView.setTag(holder);
          holder.checkbox.setTag(listModelList.get(position));
  
          //spinner
  
          holder.spinner = (Spinner) convertView.findViewById(R.id.listview_spinner);
  
          ArrayAdapter&lt;String&gt; startColorsAdapter = new ArrayAdapter&lt;String&gt;(mContext,
                  android.R.layout.simple_list_item_1,mColorNames);
          holder.spinner.setAdapter(startColorsAdapter);
          holder.spinner.setSelection(listModelList.get(position).getCount());
  
  
  
          holder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position2, long id) {
                  ListModel starModel = listModelList.get(position);
                  starModel.setCount(position2);
                  listModelList.remove(position);
                  listModelList.add(position,starModel);
              }
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
              }
          });
  
          convertView.setTag(holder);
      }else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      // initialize image resource
      holder.iamge = (ImageView) convertView.findViewById(R.id.listview_imgs);
      // setting image
      holder.iamge.setImageResource(listModelList.get(position).getImage());
  
      //textview resource
  
       holder.textView= (TextView) convertView.findViewById(R.id.listview_tv);
       holder.textView.setText(listitems[position]);
       // holder.textView.setText(listModelList.get(position).getName());
  
  
      return convertView;
  }
      private class ViewHolder{
          private Spinner spinner;
          private ImageView iamge;
          private TextView textView;
          private CheckBox checkbox;
      }
  
  
  
      @Override
      public int getViewTypeCount() {
  
      return getCount();
  }
  
      @Override
      public int getItemViewType(int position) {
  
      return position;
  }
  
  
  }
  </code></pre>