CustomListview Volley with Image 在真实设备中不起作用

CustomListview Volley with Image doesn't works in real device

谁能帮我解决这个问题。因为这个问题我卡了 3 天 -_-!

我可以使用 volley 库制作带有图像和文本的列表视图,它在模拟器中工作(我使用 genymotion 模拟器)图像和文本显示。但是当我 运行 它在我的设备 (android Jelly 4.3.0) 中时,列表视图是空的。该层是空白的(空的)。我不知道为什么。

这是我的代码

public class DaftarBarang_Layout extends Activity{

private List<Produk> produkList = new ArrayList<Produk>();
private ListView listView;
private CustomListAdapter adapter;
private ProgressDialog pDialog;
private ServerRequest serverRequest;
JSONArray member = null;
private static final String url = "http://192.168.117.1:808/Koen_CI/index.php/daftar_barang_control";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.daftarbarang_layout);

    listView = (ListView) findViewById(R.id.list);
    adapter = new CustomListAdapter(this, produkList);
    listView.setAdapter(adapter);

    btnBack = (Button)findViewById(R.id.btnBackDaftarBarang);        
    setBehavior();

 // Creating volley request obj
        JsonArrayRequest produkReq = new JsonArrayRequest(url,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d("TAG", response.toString());
                        hidePDialog();
                        // Parsing json
                        for (int i = 0; i < response.length(); i++) {
                            try {

                                JSONObject obj = response.getJSONObject(i);
                                Produk produk = new Produk();
                                produk.setNamaProduk(obj.getString("nama_produk"));
                                produk.setHargaProduk(obj.getString("harga_produk"));
                                produk.setFotoProduk(obj.getString("foto_produk"));
                                Log.d("TAG", "TAG : " + produk.getNamaProduk());    

                                // adding movie to movies array
                                produkList.add(produk);

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                        // notifying list adapter about data changes
                        // so that it renders the list view with updated data
                        adapter.notifyDataSetChanged();
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d("TAG", "Error: " + error.getMessage());
                        hidePDialog();

                    }
                });

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(produkReq);
}

我确定 url 没问题,图像 return 是 http://192.168.117.1:808/Koen_CI/gambarbaju/batik.jpg

问题是,为什么在真实设备上不显示列表视图,而在模拟器中显示列表视图..

抱歉我的英语不好,但无论如何还是谢谢..:)

这是我的 CustomListAdapter:

public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Produk> produkItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();

public CustomListAdapter(Activity activity, List<Produk> produkItems) {
    this.activity = activity;
    this.produkItems = produkItems;
}

@Override
public int getCount() {
    return produkItems.size();
}

@Override
public Object getItem(int location) {
    return produkItems.get(location);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (inflater == null)
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
        convertView = inflater.inflate(R.layout.list_row, null);

    if (imageLoader == null)
        imageLoader = AppController.getInstance().getImageLoader();
    NetworkImageView thumbNail = (NetworkImageView) convertView
            .findViewById(R.id.thumbnail);
    TextView title = (TextView) convertView.findViewById(R.id.title);
    TextView rating = (TextView) convertView.findViewById(R.id.rating);

    // getting movie data for the row
    Produk p = produkItems.get(position);

    // thumbnail image
    thumbNail.setImageUrl(p.getFotoProduk(), imageLoader);

    // title
    title.setText(p.getNamaProduk());

    // rating
    rating.setText("Harga: " + p.getHargaProduk());

    return convertView;
}

将此代码添加到您的 onCreate 或 init 方法中。

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

如果这不起作用,请 post logcat 显示警告或错误。