0

我想将每个数据库添加到列表视图的每一行......实际上我的问题是我能够从数据库中获取数据,但它没有显示在列表视图中,我的代码是:

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));}

它的显示是这样的

列表显示

我想单独显示每一行。所有行都显示在一行中。请帮帮我..

4

2 回答 2

1

添加

s = new StringBuilder();

在 for 循环的开始

于 2013-04-30T07:07:35.457 回答
0

尝试在您的列表视图中添加这一行:(您可能在列表视图中看不到分隔线)

android:divider="#000000"
android:dividerHeight="0.5dp"
android:cacheColorHint="@android:color/transparent"
于 2013-04-30T07:22:43.730 回答