在列表视图中不显示值
问题描述:
我想从数据库中获取值并在列表视图中显示所有值。 我的代码是:在列表视图中不显示值
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/meetingschedular/viewdetail.php?mdate="+viewdate.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 at= json_data.getString("attendees");
String at1=json_data.getString("title");
String at2=json_data.getString("mtime");
String at3=json_data.getString("venue");
s.append(j+"Attendees:"+at);
s.append("\nTitle:"+at1);
s.append("\nTime:"+at2);
s1.append("\nVenue:"+at3);
r.add(s.toString());
//r.add(s1.toString());
j++;
}
l.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, r));
}
catch(Exception e1)
{
e1.printStackTrace();
Toast.makeText(getBaseContext(),"Sorry No Meeting Details",Toast.LENGTH_LONG).show();
}
但是当我显示列表视图我从数据库中获取只有一个行,而不是获取数据库显示的第二排它越来越显示两次。
的PL HLP我.. :(
这里是我的XML文件
'<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/prle"
android:orientation="vertical"
tools:context=".Meetdetail1Activity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/Grey"
android:text="@string/homelinkpropose"
android:textColor="@color/blue" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@color/Grey"
android:text="@string/logoutproposemeet"
android:textColor="@color/blue" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="@string/meetdetaill"
android:textColor="@color/yellow"
android:textSize="@dimen/meetdettextsize" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:text="@string/viewdate" />
<ListView
style="@style/dividedListStyle"
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_below="@+id/textView4"
android:dividerHeight="20dp">
</ListView>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:layout_toLeftOf="@+id/textView2"
android:text="@string/viewname"
android:textColor="@color/yellow"
android:textSize="@dimen/sixtn" />
答
,你声明S和R变量?
你必须在for循环中声明ArrayList变量
检查您的xml列表视图,您可能会给出固定的大小。改变包装或填充母
答
我想你的JSON字符串,处理有一些问题,请尝试:
JSONObject object = new JSONObject(result);
JSONArray Jarray = object.getJSONArray("atendees");
for (int i = 0; i < Jarray.length(); i++) {
JSONObject Jasonobject = Jarray.getJSONObject(i);
}
OFC你必须处理这对于其他的JSON-表藏汉!
什么是s,s,s和s1 – Unknown 2013-04-29 12:31:54
尝试声明StringBuffer的内部for循环并测试一次... – Vamshi 2013-04-29 12:33:28
看起来,您将数据库中的整个值变为一个可见的String,这是您的目的吗?上面的图片看起来像你的视图,你想要显示的信息会削减字符串,因为它很小。你可以发布你的xml从listView项目? – Opiatefuchs 2013-04-29 12:33:59