Reputation: 351
I'm having a weird problem regarding the simple ListView
.
On my emulator everything is allright and the data is loaded correctly from JSON API, the data also loads on my device.
The problem is that on my emulator, the listview
is populated but on my real device, not, even if there is data from JSON, why ?
private void addItemsToListView(JSONObject message) {
try {
JSONArray jsonArray = message.getJSONArray("android");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject c = jsonArray.getJSONObject(i);
String imagePath = c.getString("path");
try {
myImages.add(new ImagesModel(i, imagePath, R.drawable.mtr));
} catch(Exception e) {
e.printStackTrace();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Upvotes: 1
Views: 1248
Reputation: 351
Got the problem, I've changed the layout from RelativeLayout to LinearLayout and it is all working fine.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/view_background"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<ProgressBar
android:id="@+id/progressBar1"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progress="@integer/abc_config_activityShortDur"
android:layout_centerInParent="true"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:minHeight="200dp"
android:minWidth="200dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/btnUploadedActivity"
android:id="@+id/imagesListViewTitle"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imagesListView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignLeft="@+id/imagesListViewTitle"
android:layout_below="@+id/imagesListViewTitle"
android:smoothScrollbar="true" />
</LinearLayout>
Upvotes: 1