2015-02-24 48 views
2

有人,幫我解決這個問題。我在3天內陷入困境,因爲這個問題-_-!CustomListview與圖像齊射不起作用的真實設備

我可以用圖像和文本使用排球庫,其作品在模擬器(我使用genymotion模擬器)的圖像和文字顯示。但是當我在我的設備(Android Jelly 4.3.0)中運行它時,listview是空的。圖層爲空白(空白)。我不知道爲什麼。

我的繼承人一塊代碼

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是好的,形象回報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; 
} 
+0

您是否添加了互聯網訪問權限? – 2015-02-24 11:26:57

+0

是的,我已經在我的Android清單中添加了互聯網訪問 – 2015-02-24 11:29:54

+0

您可以發佈您的適配器代碼嗎?或任何你有你的圖像加載器調用 – 2015-02-24 11:46:58

回答

1

將此代碼添加到您的onCreate或init方法中。

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

如果這不起作用,請發佈logcat顯示警告或錯誤。

+0

我會嘗試,但我看不到logcat。因爲我的設備沒有連接到筆記本電腦。我只是把它安裝在設備上並通過connectify-me連接 – 2015-02-24 11:35:50

+0

然後請嘗試在調試模式下連接您的設備,這將肯定解決您的問題,無需logCat,任何人都無法理解您的問題,只有想法在這裏... – IshRoid 2015-02-24 11:38:20

+0

地獄是啊,你救我的一天先生!它的工作像魅力.. 你怎麼知道我是否必須添加該代碼? StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()。permitAll()。build(); StrictMode.setThreadPolicy(policy); – 2015-02-24 11:54:32