title: Displaying JSONArray in android list view
body: <p>Trying to display the JSONArray in android listview.But i am not able to get it.</p>
  
  <p>Here is the source code</p>
  
  <pre><code>public class Period extends Activity  {
  private RadioGroup radioSexGroup;
    private RadioButton radioSexButton;
    private Button btnPeriod,btnback,btnchangestudy;
    TextView tv;
          ProgressDialog prgDialog;
    private String period;
    DBHelper dbUser = new DBHelper(Period.this);
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.period);
      ImageView image = (ImageView) findViewById(R.id.test_image);
      tv = (TextView) findViewById(R.id.display);
        Calendar c = Calendar.getInstance();
        SimpleDateFormat format4;       
       format4 = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss");    
        tv.setText(format4.format(c.getTime()));
          prgDialog = new ProgressDialog(this);
          prgDialog.setMessage("Please wait...");
          prgDialog.setCancelable(false);        
      addListenerOnButton();
    }
    public void addListenerOnButton() {
      radioSexGroup = (RadioGroup) findViewById(R.id.radioPeriod);
      btnPeriod = (Button) findViewById(R.id.btn_submit_period);
      btnchangestudy=(Button) findViewById(R.id.btn_change_study);        
      btnchangestudy.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              if(v==btnchangestudy)
              {
                      invokeWS();
          Intent intent =new Intent(Period.this,Menu.class);
          startActivity(intent);
      }
          }
  
      });
    }
  
    public void invokeWS(){   
           prgDialog.show();
           Log.d("sr...", "sri....");
           AsyncHttpClient client = new AsyncHttpClient();
               client.get("http://192.168.10.8:8080/useraccount/barcode/studyid",new AsyncHttpResponseHandler() { 
               String s, s1, s2;
               @Override
               public void onSuccess(String response) {
                   prgDialog.hide();
                   ListView list = (ListView) findViewById(R.id.mobile_list);                  
                   try {
                       List&lt;Data&gt; dataList= new ArrayList();
                       JSONArray JSON = new JSONArray(response);
                       for (int i = 0; i &lt; JSON.length(); i++) {
                           JSONObject obj = JSON.getJSONObject(i);
                           Data d = new Data();
                           d.setId(obj.getString("id"));
                           d.setNum(obj.getString("num"));
                           dataList.add(d);                     
                          }
                          ArrayAdapter&lt;Data&gt; itemsAdapter =new ArrayAdapter&lt;Data&gt;(Period.this,android.R.layout.simple_list_item_1, dataList);
                          ListView listView = (ListView) findViewById(R.id.lvItems);
                          listView.setAdapter(itemsAdapter);
                       } catch (JSONException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                       }
  
         }
               @Override
               public void onFailure(int statusCode, Throwable error,
                   String content) {
                   prgDialog.hide();
                   if(statusCode == 404){
                       Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
                   } 
                   else if(statusCode == 500){
                       Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
                   } 
                   else{
                       Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
                   }
               }
           });
      }
  
      public void showMessage(String title, String message) {
          Builder builder = new Builder(this);
          builder.setCancelable(true);
          builder.setTitle(title);
          builder.setMessage(message);
          builder.show();
          }
  
  
  
     }
  </code></pre>
  
  <p>and the following output I am getting in logcat</p>
  
  <pre><code>12-07 16:34:40.723: D/sr...(276): sri....
  
  12-07 16:34:41.003: D/dalvikvm(276): GC_FOR_MALLOC freed 12550 objects / 792856 bytes in 159ms
  12-07 16:34:43.943: D/ss(276): 14
  12-07 16:34:43.943: D/sw(276): testone
  12-07 16:34:43.943: D/ss(276): 13
  12-07 16:34:43.943: D/sw(276): kjh
  12-07 16:34:43.943: D/ss(276): 12
  12-07 16:34:43.943: D/sw(276): 321
  12-07 16:34:43.943: D/ss(276): 11
  12-07 16:34:43.943: D/sw(276): clinical
  12-07 16:34:43.943: D/ss(276): 10
  12-07 16:34:43.943: D/sw(276): fsd
  12-07 16:34:43.953: D/ss(276): 9
  12-07 16:34:43.953: D/sw(276): 2015
  12-07 16:34:43.953: D/ss(276): 8
  12-07 16:34:43.953: D/sw(276): 133
  12-07 16:34:43.953: D/ss(276): 7
  12-07 16:34:43.953: D/sw(276): 007
  12-07 16:34:43.953: D/ss(276): 6
  12-07 16:34:43.953: D/sw(276): TESTSTUDY
  12-07 16:34:43.963: D/ss(276): 5
  12-07 16:34:43.963: D/sw(276): 111
  12-07 16:34:43.973: D/ss(276): 4
  12-07 16:34:43.973: D/sw(276): 1000
  12-07 16:34:43.973: D/ss(276): 3
  12-07 16:34:43.973: D/sw(276): 121
   12-07 16:34:43.983: D/ss(276): 2
  12-07 16:34:43.983: D/sw(276): s one
  12-07 16:34:43.983: D/ss(276): 1
  12-07 16:34:43.983: D/sw(276): Default_Study
  </code></pre>
  
  <p>please somebody help me. I am new to android.</p>
  
  <p>thanks in advance</p>
  
  <p>this is period.xml</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"
     android:orientation="horizontal"&gt; 
       &lt;TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal" &gt;  
            &lt;TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:gravity="center_vertical|center_horizontal"&gt;    
                 &lt;ImageView 
                  android:id="@+id/test_image"
                  android:src="@drawable/logo4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                       /&gt;           
            &lt;TextView
      android:id="@+id/display"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="right"
      android:layout_weight="1"
      android:text= /&gt;
       &lt;/TableRow&gt;
          &lt;TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" &gt;  
                &lt;RadioGroup
      android:id="@+id/radioPeriod"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
      &lt;RadioButton
          android:id="@+id/r1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/radio_1" 
           android:checked="true"/&gt;
      &lt;RadioButton
          android:id="@+id/r2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/radio_2" /&gt;
      &lt;/RadioGroup&gt;
      &lt;/TableRow&gt;
       &lt;TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" &gt;
                &lt;Button
      android:id="@+id/btn_submit_period"
      android:layout_width="10dp"
      android:layout_height="40dp"
      android:text="@string/submitPeriod" 
      android:onClick="onClick"/&gt; 
       &lt;/TableRow&gt;
        &lt;TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" &gt; 
                &lt;Button
      android:id="@+id/btn_change_study"
      android:layout_width="10dp"
      android:layout_height="40dp"
      android:text="@string/changestudy" 
      android:onClick="onClick"/&gt; 
      &lt;/TableRow&gt;     
      &lt;TableRow
                android:id="@+id/tableRow5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" &gt;    
                &lt;Button
          android:id="@+id/btnLogin"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dip"
          android:background="#ff6347"
          android:onClick="loginUser"
          android:text="change studyyy"
          android:textColor="#fff" /&gt;      
          &lt;/TableRow&gt;
          &lt;/TableLayout&gt;
           &lt;/LinearLayout&gt;
  </code></pre>