ListView不在实际设备上显示

ListView不在实际设备上显示

本文介绍了Android ListView不在实际设备上显示,但在模拟器上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于简单的ListView,我遇到了一个奇怪的问题.在我的模拟器上,一切都很好,并且可以从JSON API正确加载数据,数据也可以加载到我的设备上.问题是,在我的仿真器中,填充了listview,但是在我的真实设备上却没有,即使存在JSON中的数据,为什么?

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();
    }
}

推荐答案

解决了这个问题,我将布局从RelativeLayout更改为LinearLayout,并且一切正常.

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>

这篇关于Android ListView不在实际设备上显示,但在模拟器上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:04