私のjsonファイルは単一の画像のみを表示し、すべての画像を表示するのではなく、以下のテキストは私のコードですthsは私のスクリーンショットです
そして私はこのように作りたい
私のコードで何が問題なのか教えてください。3つの画像とテキストビューをすべて表示しないのはなぜですか?????
{
"worldpopulation": [{
"rank": 1,
"name": "BREAKFAST",
"url": "http://niel986.files.wordpress.com/2012/07/fast-food.jpg"
}, {
"rank": 2,
"name2": "LUNCH ",
"url2": "http://www.bubblews.com/assets/images/news/1107772406_1370520219.gif"
}, {
"rank": 3,
"name3": "SUPPER",
"url3": "http://2.bp.blogspot.com/_JU_j7jj5TjU/TSBQKRukf1I/AAAAAAAAAs8/X1w5_z6pjwQ / s1600 / chicken - biryani.jpg "
}
]
}
ImageView img1 = (ImageView) findViewById(R.id.img1);
TextView txt1 = (TextView) findViewById(R.id.txt1);
ImageView img2 = (ImageView) findViewById(R.id.img2);
TextView txt2 = (TextView) findViewById(R.id.txt2);
ImageView img3 = (ImageView) findViewById(R.id.img3);
TextView txt3 = (TextView) findViewById(R.id.txt3);
cla3 = new CategoryListAdapter3(thirdstep.this);
MenuSelect = Utils.MenuSelect;
try {
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(),
15000);
HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
HttpUriRequest request = new HttpGet(MenuSelect);
HttpResponse response = client.execute(request);
InputStream atomInputStream = response.getEntity().getContent();
BufferedReader in = new BufferedReader(new
InputStreamReader(atomInputStream));
String line;
String str = "";
while ((line = in.readLine()) != null){
str += line;
}
JSONObject json = new JSONObject(str);
JSONArray data = json.getJSONArray("worldpopulation");
for ( int i = 0; i < data.length(); i++ )
{
JSONObject jsonOrder = (JSONObject)data.get(i);
int rabk = jsonOrder.getInt("rank");
String name = jsonOrder.getString("name");
String url1 = jsonOrder.getString("url");
txt1.setText(name);
Bitmap bitmap =
BitmapFactory.decodeStream((InputStream)new URL(url1).getContent());
img1.setImageBitmap(bitmap);
int rabk2 = jsonOrder.getInt("rank2");
String name2 = jsonOrder.getString("name2");
String url2 = jsonOrder.getString("url2");
txt2.setText(name2);
Bitmap bitmap2 =
BitmapFactory.decodeStream((InputStream)new URL(url2).getContent());
img2.setImageBitmap(bitmap2);
int rabk3 = jsonOrder.getInt("rank3");
String name3 = jsonOrder.getString("name3");
String url3 = jsonOrder.getString("url3");
txt3.setText(name3);
Bitmap bitmap3 =
BitmapFactory.decodeStream((InputStream)new URL(url3).getContent());
img3.setImageBitmap(bitmap3);
}
以下は私のxmlコードです:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="70dp"
android:layout_height="80dp"
android:contentDescription="@null"
android:background="@drawable/imagebgborder"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/img3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>