我想將每個數據庫放到listview的每一行...... 實際上,我的問題是我能夠從數據庫中獲取數據,但它不能在列表視圖中顯示出來 my代碼:將數據庫的每一行映射到listview的每一行
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/meetingschedular/fetchmeet.php?uid="+vwname.getText().toString());
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
}
//Convert response to string
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
}
//END Convert response to string
try
{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++)
{
JSONArray innerJsonArray = jArray.getJSONArray(i);
JSONObject json_data = innerJsonArray.getJSONObject(0);
String at1=json_data.getString("title");
String at= json_data.getString("mdate");
String at2=json_data.getString("mtime");
String at3=json_data.getString("venue");
String at4=json_data.getString("organiser");
s.append("\nTitle:"+at1);
s.append("\ndate:"+at);
s.append("\nTime:"+at2);
s.append("\nVenue:"+at3);
s.append("\nOrganiser:"+at4);
r.add(s.toString());
}
l.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, r));}
其顯示這樣
我想seperately顯示每一行。所有行都顯示在一行中。 PLS HLP我..
我已經做到了,但沒有用,數據庫的所有行都顯示在單個listview行中。 – priya89 2013-04-30 07:25:54
編輯將'sb'改爲's'。嘗試爲變量使用良好的命名。每當循環運行時,您的當前代碼都會附加's',因此您需要重新初始化變量's'。如果你已經改變了你的代碼中的任何東西,請更新 – Naveen 2013-04-30 07:36:48
這個問題,非常感謝你的工作....... – priya89 2013-04-30 07:43:05