title: How do i add spinner inside listview row in android?
body: <p>I am developing an app in this i have populate <code>listview</code> with <code>json</code> parser. Now i have to add local spinner array inside this <code>listview</code> single row. 
  How do i add locally spinner array inside this <code>listview</code> row. And also i want to get selected spinner values of <code>listview</code>. Following is my code please suggest me.</p>
  
  <pre><code>//activity
  public class MyModifyPgmLvAddUserActivity1 extends AppCompatActivity {
  
              private DBManager dbManager;
              private ListView listView, listView1;
              Toolbar toolbar;
              private String TAG = MyModifyPgmLvAddUserAdapter.class.getSimpleName();
              private ProgressDialog pDialog;
              //    private SimpleCursorAdapter adapter;
              MyModifyPgmLvAddUserAdapter1 adapter;
  
  
              static String RANK = "AsanaId";
              static String COUNTRY = "Asananame";
              static String POPULATION = "repetation";
  
              ArrayList&lt;PojoList&gt; SubjectList = new ArrayList&lt;PojoList&gt;();
  
              final static String[] mSpinnerItems = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
  
              private static String url = "http://www.test.com/ypAndroid/api/getDefaultProgramlist";
              String asananame, asanaid,duration, imageurl, imageversion, audiourl, audioversion, videourl, videoversion;
  
              String sid;
              boolean selected;
              String id;
              String[] subject = null;
              String[] spinner = null;
              String title;
              long id1;
              Button btnCreate;
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
  
                  setContentView(R.layout.activity_my_modifypgm_lv_add_user);
  
                  btnCreate = (Button) findViewById(R.id.button_submit);
  
                  dbManager = new DBManager(this);
                  dbManager.open();
  
  
                  Intent i = getIntent();
                  id= i.getStringExtra("id");
                  subject = i.getStringArrayExtra("subject");
                  spinner = i.getStringArrayExtra("spinner");
                  title= i.getStringExtra("title");
  
                  id1= Long.parseLong(id);
  
                  SubjectList = new ArrayList&lt;&gt;();
  
                  listView = (ListView) findViewById(R.id.listview);
  
                  //Net Connection
                  ConnectivityManager conMgr =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                  NetworkInfo netInfo = conMgr.getActiveNetworkInfo();
                  if (netInfo == null){
                      AlertDialog.Builder alert = new AlertDialog.Builder(MyModifyPgmLvAddUserActivity1.this);
                      //  new AlertDialog.Builder(MyModifyProgramEditDeleteActivity.this)
                      alert.setTitle(getResources().getString(R.string.app_name));
                      alert.setMessage(getResources().getString(R.string.no_internet));
                      alert.setPositiveButton("OK", null).show();
  
                      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int whichButton) {
                              //Do something here where "ok" clicked and then perform intent from activity context
                              Intent intent = new Intent(MyModifyPgmLvAddUserActivity1.this, MyYogaPosesSubMenuActivity.class);
                              MyModifyPgmLvAddUserActivity1.this.startActivity(intent);
                          }
                      });
                      alert.show();
                  }
                  else {
                      new MyModifyPgmLvAddUserActivity1.DownloadJSON().execute();
                  }
  
  
                  btnCreate.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
  
                          checkButtonClick();
                          Intent modify_intent = new Intent(MyModifyPgmLvAddUserActivity1.this, MyModifySavedProgramActivity1.class);
                          modify_intent.putExtra("subject", spinner);
                          modify_intent.putExtra("spinner", subject);
                          modify_intent.putExtra("id", id);
                          modify_intent.putExtra("title", title);
                          startActivity(modify_intent);
  
                      }
                  });
  
  
              }
  
              private void checkButtonClick() {
  
                  ArrayList&lt;String&gt; list1= new ArrayList&lt;&gt;();
                  ArrayList&lt;String&gt; list2= new ArrayList&lt;&gt;();
               //   ArrayList&lt;String&gt; list3= new ArrayList&lt;&gt;();
  
                  PojoList pojo = null;
                  ArrayList&lt;PojoList&gt; countryList = adapter.SubjectListTemp;
                  for (int i = 0; i &lt; countryList.size(); i++) {
  
                      pojo = countryList.get(i);
  
                      if (pojo.isSelected()) {
                          // responseText.append("\n" + country.getName());
  
                          list1.add(pojo.getAsanName());
  
                        //  list2.add(convertArrayToString(subject));
                          list2.add(pojo.getAsanId());
                         // list2.add(convertArrayToString(spinner));
  
                      }
                  }
  
                  String [] aIds = list1.toArray(new String[list1.size()]);
                  String [] aNames = list2.toArray(new String[list2.size()]);
  
                  dbManager.update(id1, aIds, aNames);
                  //   dbManager.insert(title, names, spinner);
                  //  dbManager.set_datetime_next(id, names, spinner);
              }
  
              public static String[] convertStringToArray(String str){
                  String[] arr = str.split(strSeparator);
                  return arr;
              }
  
              private class DownloadJSON extends AsyncTask&lt;Void, Void, Void&gt; {
  
                  private ProgressDialog pDialog;
  
                  @Override
                  protected void onPreExecute() {
                      super.onPreExecute();
                      // Showing progress dialog
                      pDialog = new ProgressDialog(MyModifyPgmLvAddUserActivity1.this);
                      pDialog.setMessage("Please wait...");
                      pDialog.setCancelable(false);
                      pDialog.show();
                  }
  
                  @Override
                  protected Void doInBackground(Void... arg0) {
                      HttpHandler sh = new HttpHandler();
                      String jsonStr = sh.makeServiceCall(url);
  
                      PojoList pojo;
  
                      Log.e(TAG, "Response from url: " + jsonStr);
  
                      if (jsonStr != null) {
  
                          try {
                              JSONObject o = new JSONObject(jsonStr);
                              JSONArray restaurants = o.getJSONArray("getdefaultprogramlist");
  
                              for (int k = 0; k &lt; restaurants.length(); k++) {
  
                                  JSONObject rating1 = restaurants.getJSONObject(k);
  
                                  asanaid = rating1.getString("programid");
                                  Log.d("TestJson asanaid", asanaid);
                                  asananame = rating1.getString("programname");
                                  Log.d("TestJson asananame", asananame);
  
                                  for (int i = 0; i &lt; restaurants.length(); i++) {
                                      JSONObject restaurant = restaurants.getJSONObject(i);
  
                                      JSONArray ratings = restaurant.getJSONArray("ProgramItem");
                                      for (int j = 0; j &lt; ratings.length(); j++) {
  
                                          JSONObject rating = ratings.getJSONObject(j);
                                          String stepnumber = rating.getString("AsanaId");
                                          Log.d("TestJson stepnumber", stepnumber);
                                          String stepdesc = rating.optString("Asananame");
                                          Log.d("TestJson stepdesc", stepdesc);
                                          String stepimg = rating.getString("duration");
                                          Log.d("TestJson stepimg", stepimg);
                                          String stepimgeversion = rating.getString("repetation");
                                          Log.d("TestJson stepimgvrsion ", stepimgeversion);
  
  
          //                               int sid = Integer.parseInt(convertArrayToString(mSpinnerItems));
                                          pojo = new PojoList(stepnumber, stepdesc, selected, convertArrayToString(mSpinnerItems));
  
                                          SubjectList.add(pojo);
  
  
                                          System.out.println("Size of Entry list from Map: " + SubjectList.size());
  
                                      }
                                  }
                              }
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      } else {
                          Log.e(TAG, "Couldn't get json from server.");
                          runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  Toast.makeText(getApplicationContext(),
                                          "Couldn't get json from server. Check LogCat for possible errors!",
                                          Toast.LENGTH_LONG)
                                          .show();
                              }
                          });
                      }
                      return null;
                  }
  
                  @Override
                  protected void onPostExecute(Void args) {
  
                      if (pDialog.isShowing())
                          pDialog.dismiss();
  
                      adapter = new MyModifyPgmLvAddUserAdapter1(MyModifyPgmLvAddUserActivity1.this, R.layout.my_yoga_poseslv_add_user_single_item, SubjectList);
                      listView.setAdapter(adapter);
                  }
              }
  
  
              public static String strSeparator = ",";
              public static String convertArrayToString(String[] array){
                  String str = "";
                  for (int i = 0;i&lt;array.length; i++) {
                      str = str+array[i];
                      // Do not append comma at the end of last element
                      if(i&lt;array.length-1){
                          str = str+strSeparator;
                      }
                  }
                  return str;
              }
          } 
  
      //PojoList
      public class PojoList {
  
          String AsanName = null;
          String AsanId = null;
          boolean selected = false;
          String sid = null;
          String sarray = null;
          boolean sSelected = false;
  
          public PojoList(String Sname, String SFullForm, boolean selected, String Sarray) {
  
              super();
  
              this.AsanName = Sname;
  
              this.AsanId = SFullForm;
  
              this.selected = selected;
  
              this.sarray = Sarray;
  
             // this.sid = Sid;
          }
  
          public String getAsanName() {
  
              return AsanName;
  
          }
          public void setAsanName(String code) {
  
              this.AsanName = code;
  
          }
          public String getAsanId() {
  
              return AsanId;
  
          }
          public void setAsanId(String id) {
  
              this.AsanId = id;
  
          }
  
          @Override
          public String toString() {
  
              return  AsanName + " " + AsanId ;
  
          }
  
          public boolean isSelected() {
              return selected;
          }
          public void setSelected(boolean selected) {
              this.selected = selected;
          }
  
          public String getId() {
              return sarray;
          }
          public void setId(String sarray) {
              this.sarray = sarray;
          }
      }
  </code></pre>
  
  <p>//adapter</p>
  
  <pre><code>public class MyModifyPgmLvAddUserAdapter1 extends ArrayAdapter&lt;PojoList&gt; {
  
      public ArrayList&lt;PojoList&gt; MainList;
  
      public ArrayList&lt;PojoList&gt; SubjectListTemp;
  
      Context context;
  
  
      private String[] mSpinnerItems = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
  
      //  public ListAdapter.SubjectDataFilter subjectDataFilter ;
  
      public MyModifyPgmLvAddUserAdapter1(Context context, int id, ArrayList&lt;PojoList&gt; subjectArrayList) {
  
          super(context, id, subjectArrayList);
  
          this.SubjectListTemp = new ArrayList&lt;PojoList&gt;();
  
          this.SubjectListTemp.addAll(subjectArrayList);
  
          this.MainList = new ArrayList&lt;PojoList&gt;();
  
          this.MainList.addAll(subjectArrayList);
      }
  
      public class ViewHolder {
  
          TextView SubjectName, aId;
          TextView SubjectFullForm, aName;
          CheckBox cb;
          Spinner spinner;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          ViewHolder holder = null;
  
          if (convertView == null) {
  
              LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
              convertView = vi.inflate(R.layout.my_yoga_poseslv_add_user_single_item, null);
  
              holder = new ViewHolder();
              holder.aName = (TextView) convertView.findViewById(R.id.listview_tv);
  
              holder.aId = (TextView) convertView.findViewById(R.id.listview_id);
  
              holder.cb = (CheckBox) convertView.findViewById(R.id.listview_cb);
  
              holder.spinner = (Spinner) convertView.findViewById(R.id.listview_spinner);
  
              holder.cb.setOnClickListener( new View.OnClickListener() {
                  public void onClick(View v) {
                      CheckBox cb = (CheckBox) v ;
                      PojoList pojo = (PojoList) cb.getTag();
                      Toast.makeText(getContext(),
                              "Clicked on Checkbox: " + cb.getText() +
                                      "Clicked on Checkbox: "+
                                      " is " + cb.isChecked() + "Id is : "+ pojo.getAsanName(),
                              Toast.LENGTH_LONG).show();
                      pojo.setSelected(cb.isChecked());
                  }
              });
  
              ArrayAdapter&lt;String&gt; spinnerAdapter = new ArrayAdapter&lt;String&gt;(getContext(),
                      android.R.layout.simple_list_item_1, mSpinnerItems);
              holder.spinner.setAdapter(spinnerAdapter);
  
              convertView.setTag(holder);
  
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          PojoList pojo = SubjectListTemp.get(position);
  
          holder.aName.setText(pojo.getAsanName());
  
          holder.cb.setText(pojo.getAsanId());
  
          holder.cb.setChecked(pojo.isSelected());
  
          holder.cb.setTag(pojo);
  
          //  holder.spinner.setSelection(Integer.parseInt(pojo.getId()));
          holder.spinner.setSelected(pojo.isSelected());
  
          return convertView;
  
      }
  
  }
  </code></pre>
  
  <p>//list row</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="horizontal"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:background="#cccccc"&gt;
  
  
          &lt;Spinner
              android:id="@+id/listview_spinner"
              style="@style/AppTheme"
              android:layout_width="42dp"
              android:layout_height="40dp"
              android:layout_alignParentEnd="true"
              android:layout_alignParentRight="true"
              android:layout_centerVertical="true"
              android:layout_marginEnd="21dp"
              android:layout_marginRight="21dp" /&gt;
  
          &lt;CheckBox
              android:id="@+id/listview_cb"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text=""
              android:layout_marginTop="2dp"
              android:layout_marginLeft="4dp"
              android:layout_alignParentTop="true"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true" /&gt;
  
          &lt;TextView
              android:id="@+id/listview_tv"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="17dp"
              android:layout_marginStart="17dp"
              android:text="TextView"
              android:textSize="1sp"
              android:visibility="invisible"
              android:layout_centerVertical="true"
              android:layout_toRightOf="@+id/listview_imgs"
              android:layout_toEndOf="@+id/listview_imgs" /&gt;
  
  
          &lt;TextView
              android:id="@+id/listview_id"
              android:layout_width="wrap_content"
              android:visibility="invisible"
              android:layout_height="wrap_content"
              android:layout_alignEnd="@+id/listview_spinner"
              android:layout_alignRight="@+id/listview_spinner"
              android:layout_alignTop="@+id/listview_imgs"
              android:text="TextView" /&gt;
  
  
  
      &lt;/RelativeLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>