1
我试过寻找其他问题,其中大部分都是在滚动视图中使用listview,但我没有滚动视图,所以没有多大的帮助。我相信这是我想念的小事,但我似乎无法找到它。下面是打印出3个animalNames到列表视图,但只打印第一个。ListView只打印来自ArrayList的第一个值
JSONArray mainNode = new JSONArray(loadJSONFromAsset()); // call the connection to json
ArrayList<String> animalsArray = new ArrayList<String>();
if(mainNode != null) //puts the values into an array
{
for(int i=0;i<mainNode.length();i++)
{
JSONObject eachObject = mainNode.getJSONObject(i);
animalsArray.add(eachObject.getString("animalName"));
}
//prints array to check
for(String stuff : animalsArray)
{
Log.i("name", stuff);
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, animalsArray);
animalsList = (ListView) findViewById(R.id.animalList);
animalsList.setAdapter(arrayAdapter);
}
这会打印出3个值我的JSON来logcat的范围内,所以我敢肯定,这是越来越值,我只是不确定,为什么它只是打印第一位置到列表中。
万一它有任何用处,我目前的布局如下。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/animalList"/>
任何想法,为什么它仅打印第一,将不胜感激。
谢谢。
只显示'Log.i(“名称”,东西)的一个值;'线? – 2015-03-02 08:27:00
@ρяσѕρєяK_这将在我的JSON中打印出3个值logcat._他提到了它。 – Hemanth 2015-03-02 08:28:19
不,这是打印所有3,因此,为什么我知道价值在那里,让我更加困惑! – Navvy 2015-03-02 08:28:28