Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListActivity
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12403957/android-listview-with-simple-adapter">Android ListView with Simple Adapter</a> </p> </blockquote> <p>This is my first Activity.</p> <pre><code>public class CheckAvailability extends Activity{ Button but1,but2; EditText brName; TextView txt1; String text; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.availability); brName =(EditText)findViewById(R.id.editText1); but1 = (Button)findViewById(R.id.button5); but2 = (Button)findViewById(R.id.button6); txt1 = (TextView)findViewById(R.id.textView3); but1.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ String result = null; InputStream is = null; StringBuilder sb=null; ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;(); //ArrayList&lt;HashMap&lt;String, String&gt;&gt; contactList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); postParameters.add(new BasicNameValuePair("branchname", brName.getText().toString())); //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2:8080/hello/AvailabilityResponse"); httppost.setEntity(new UrlEncodedFormEntity(postParameters)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection"+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line="0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result=sb.toString(); }catch(Exception e){ Log.e("log_tag", "Error converting result "+e.toString()); } Intent intent = new Intent(CheckAvailability.this , ListAtmActivity.class); intent.putExtra("key", result); startActivity(intent);} }); </code></pre> <p>from this Activity I'm calling my second activity with that results string. This is my second activity.</p> <pre><code> public class ListAtmActivity extends Activity{ private static String url ="http://10.0.2.2:8080/hello/AvailabilityResponse"; private static final String TAG_ID = "id"; private static final String ATM_NO = "atmbrno"; private static final String ATM_PLACE = "atmbrname"; static InputStream is = null; static String json = ""; static JSONArray jObj = null; JSONArray contacts=null; public class ListViewA extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_view2); ListView lv= (ListView)findViewById(R.id.listview); String[] from = new String[] {"col_1", "col_2"}; int[] to = new int[] { R.id.item2, R.id.item3}; String brName=getIntent().getExtras().getString("key"); List&lt;HashMap&lt;String, String&gt;&gt; fillMaps = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); try { contacts = new JSONArray(brName); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } try{ for(int i = 0; i &lt; contacts.length(); i++){ JSONObject json_data = contacts.getJSONObject(i); System.out.print(contacts.length()); String atm_id = json_data.getString(ATM_NO); String atm_name = json_data.getString(ATM_PLACE); HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("col_1", atm_id); map.put("col_2", atm_name); fillMaps.add(map); } } catch(JSONException e) { e.printStackTrace(); } SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to); lv.setAdapter(adapter); } }} </code></pre> <p>but I can't get any out put to my interface...only blank screen display. what's wrong with this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload