我正在尝试从数据库中获取值并在列表视图中显示所有值。我的代码是:
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();
}
但是当我显示列表视图时,我只从数据库中获取一行,并且它显示了两次,而数据库的第二行没有显示。
请帮帮我.. :(
这是我的 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" />