title: How to put data in Sub Item on ListView Android Studio
body: <p>I am following this tutorial on how to search the data in a database and after finishing it, I realized that there is a sub item in the list view. How can I use the sub item in the list view? Since in the upper part I can output the name, I would like to output their contact number on the sub item part. How can I do that? Here is the UI of the search app(sry I cant post the pic it says &quot;you need atleast 10 repu&quot;): <a href="https://i.stack.imgur.com/t4ZyQ.png" rel="nofollow noreferrer">https://i.stack.imgur.com/t4ZyQ.png</a></p>
  <p>Here is the code I followed:</p>
  <p>Search.java</p>
  <pre><code>    private Button move;
  
      ListView SubjectListView;
      ProgressBar progressBarSubject;
      String ServerURL = &quot;http://192.168.1.22/loginregister/search/Search.php&quot;;
      EditText editText ;
      List&lt;String&gt; listString = new ArrayList&lt;String&gt;();
      ArrayAdapter&lt;String&gt; arrayAdapter ;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_search);
  
          move=findViewById(R.id.button);
          move.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(Search.this, Ticket.class);
                  startActivity(intent);
              }
          });
  
          SubjectListView = (ListView)findViewById(R.id.listview1);
  
          progressBarSubject = (ProgressBar)findViewById(R.id.progressBar);
  
          editText = (EditText)findViewById(R.id.edittext1);
  
          new GetHttpResponse(Search.this).execute();
  
  
  
          editText.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
                  Search.this.arrayAdapter.getFilter().filter(charSequence);
  
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
  
              }
          });
  
  
  
      }
  
      private class GetHttpResponse extends AsyncTask&lt;Void, Void, Void&gt;
      {
          public Context context;
  
          String ResultHolder;
  
          public GetHttpResponse(Context context)
          {
              this.context = context;
          }
  
          @Override
          protected void onPreExecute()
          {
              super.onPreExecute();
          }
  
          @Override
          protected Void doInBackground(Void... arg0)
          {
              HttpServicesClass httpServiceObject = new HttpServicesClass(ServerURL);
              try
              {
                  httpServiceObject.ExecutePostRequest();
  
                  if(httpServiceObject.getResponseCode() == 200)
                  {
                      ResultHolder = httpServiceObject.getResponse();
  
                      if(ResultHolder != null)
                      {
                          JSONArray jsonArray = null;
  
                          try {
                              jsonArray = new JSONArray(ResultHolder);
  
                              JSONObject jsonObject;
  
                              for(int i=0; i&lt;jsonArray.length(); i++)
                              {
                                  jsonObject = jsonArray.getJSONObject(i);
  
                                  listString.add(jsonObject.getString(&quot;name&quot;).toString()) ;
  
                              }
                          }
                          catch (JSONException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                      }
                  }
                  else
                  {
                      Toast.makeText(context, httpServiceObject.getErrorMessage(), Toast.LENGTH_SHORT).show();
                  }
              }
              catch (Exception e)
              {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result)
  
          {
              progressBarSubject.setVisibility(View.GONE);
  
              SubjectListView.setVisibility(View.VISIBLE);
  
              arrayAdapter = new ArrayAdapter&lt;String&gt;(Search.this,android.R.layout.simple_list_item_2, android.R.id.text1, listString);
  
              SubjectListView.setAdapter(arrayAdapter);
  
          }
      }
  }
  </code></pre>
  <p>HttpServiceClass.Java</p>
  <pre><code>    public int responseCode;
  
      public String message;
  
      public String response;
  
      public ArrayList&lt;NameValuePair&gt; ArrayListParams;
  
      public ArrayList &lt;NameValuePair&gt; headers;
  
      public String UrlHolder;
  
      public String getResponse()
      {
          return response;
      }
  
      public String getErrorMessage()
      {
          return message;
      }
  
      public int getResponseCode()
      {
          return responseCode;
      }
  
      public HttpServicesClass(String url)
      {
          HttpServicesClass.this.UrlHolder = url;
  
          ArrayListParams = new ArrayList&lt;NameValuePair&gt;();
  
          headers = new ArrayList&lt;NameValuePair&gt;();
      }
  
      public void AddParam(String name, String value)
      {
          ArrayListParams.add(new BasicNameValuePair(name, value));
      }
  
      public void AddHeader(String name, String value)
      {
          headers.add(new BasicNameValuePair(name, value));
      }
  
      public void ExecuteGetRequest() throws Exception
      {
          String MixParams = &quot;&quot;;
  
          if(!ArrayListParams.isEmpty())
          {
              MixParams += &quot;?&quot;;
  
              for(NameValuePair p : ArrayListParams)
              {
                  String paramString = p.getName() + &quot;=&quot; + URLEncoder.encode(p.getValue(),&quot;UTF-8&quot;);
  
                  if(MixParams.length() &gt; 1)
                  {
                      MixParams  +=  &quot;&amp;&quot; + paramString;
                  }
                  else
                  {
                      MixParams += paramString;
                  }
              }
          }
  
          HttpGet httpGet = new HttpGet(UrlHolder + MixParams);
  
          for(NameValuePair h : headers)
          {
              httpGet.addHeader(h.getName(), h.getValue());
          }
  
          executeRequest(httpGet, UrlHolder);
      }
  
      public void ExecutePostRequest() throws Exception
      {
          HttpPost httpPost = new HttpPost(UrlHolder);
          for(NameValuePair h : headers)
          {
              httpPost.addHeader(h.getName(), h.getValue());
          }
  
          if(!ArrayListParams.isEmpty())
          {
              httpPost.setEntity(new UrlEncodedFormEntity(ArrayListParams, HTTP.UTF_8));
          }
  
          executeRequest(httpPost, UrlHolder);
      }
  
      private void executeRequest(HttpUriRequest request, String url)
      {
          HttpParams httpParameters = new BasicHttpParams();
  
          HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
  
          HttpConnectionParams.setSoTimeout(httpParameters, 10000);
  
          HttpClient httpClient = new DefaultHttpClient(httpParameters);
  
          HttpResponse httpResponse;
          try
          {
              httpResponse = httpClient.execute(request);
              responseCode = httpResponse.getStatusLine().getStatusCode();
              message = httpResponse.getStatusLine().getReasonPhrase();
  
              HttpEntity entity = httpResponse.getEntity();
              if (entity != null)
              {
                  InputStream inputStream = entity.getContent();
  
                  response = convertStreamToString(inputStream);
  
                  inputStream.close();
              }
          }
          catch (ClientProtocolException e)
          {
              httpClient.getConnectionManager().shutdown();
              e.printStackTrace();
          }
          catch (IOException e)
          {
              httpClient.getConnectionManager().shutdown();
              e.printStackTrace();
          }
      }
  
      private String convertStreamToString(InputStream is)
      {
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
  
          StringBuilder stringBuilder = new StringBuilder();
  
          String line = null;
          try
          {
              while ((line = bufferedReader.readLine()) != null)
              {
                  stringBuilder.append(line + &quot;\n&quot;);
              }
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
          finally
          {
              try
              {
                  is.close();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
          }
          return stringBuilder.toString();
      }
  
  }
  </code></pre>