我想将每个数据库放到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));}
它显示如下
我想单独显示每一行。所有行都显示在一行中。请帮我..
答案 0 :(得分:1)
添加
s = new StringBuilder();
在for循环开始时
答案 1 :(得分:0)
尝试在列表视图中添加此行:(您可能无法在列表视图中看到分隔符)
android:divider="#000000"
android:dividerHeight="0.5dp"
android:cacheColorHint="@android:color/transparent"