Android:检查Arraylist是否为空JSON



我使用https://github.com/thest1/LazyList作为我的列表视图

我想知道我该如何检查listview是空的还是空的?

这是执行后的示例代码

@Override
        protected void onPostExecute(Void args) {
            // Locate the listview in listview_main.xml

            // Pass the results into ListViewAdapter.java
            adapter = new LvOrderSumAdapter(OrderSum.this, arraylist);
            // Set the adapter to the ListView
            listview.setAdapter(adapter);
            listview.getAdapter().getCount();
            String count = ""+listview.getAdapter().getCount(); 
            items.setText(count);

            // Close the progressdialog
            mProgressDialog.dismiss();

        }

请帮忙!我从我搜索的中尝试了这个代码

    if(!arraylist.isEmpty()){
            listview = (ListView) findViewById(R.id.listOrderSummary);
            // Pass the results into ListViewAdapter.java
            adapter = new LvOrderSumAdapter(OrderSum.this, arraylist);
            // Set the adapter to the ListView
            listview.setAdapter(adapter);
            listview.getAdapter().getCount();
            String count = ""+listview.getAdapter().getCount(); 
            items.setText(count);
            //o_total.setText("aaa");

            // Close the progressdialog
            mProgressDialog.dismiss();
            }else{  String msg = "No records found in Database!";
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                 Intent home_in = new Intent ( OrderSum.this,
                            Home.class ); 
                 startActivity(home_in); 
                 overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
            }

但我仍然得到错误

Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject"

检查listView是否为空:

listView != null;

检查列表视图是否没有元素:

listView.getAdapter().getCount()<=0;

最新更新