Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android mysql列表视图_Android_Mysql - Fatal编程技术网

android mysql列表视图

android mysql列表视图,android,mysql,Android,Mysql,我有一个问题,我有一个简单的mysql数据库,有一个名称和地址表, 我能够获得相同的json数组,但我无法填充listview。请帮助我假定您已经知道如何使用ListView控件并使用adpater,那么您需要通过扩展BaseAdapter,然后重写getCount(),getItem(),getItemId()和getView()方法来创建自定义适配器 例如,您的BaseAdapter实现可能采用JSONArray,可能是这样的 public class JSONAdapter extends

我有一个问题,我有一个简单的mysql数据库,有一个名称和地址表,
我能够获得相同的json数组,但我无法填充listview。请帮助我假定您已经知道如何使用
ListView
控件并使用adpater,那么您需要通过扩展
BaseAdapter
,然后重写
getCount()
getItem()
getItemId()
getView()
方法来创建自定义适配器

例如,您的BaseAdapter实现可能采用
JSONArray
,可能是这样的

public class JSONAdapter extends BaseAdapter {
   private JSONArray array = null;
   public JSONAdapter(JSONArray data) {
      this.array=data;
   }
   public int getCount() {
      return array.length();
   }
   public Object getItem(int position) {
      return array.get(position);
   }
   public long getItemId(int position) {
      return position;
   }
   public View getView(int position, View currentView, ViewGroup parent) {
      // get the current item from the json array
      JSONObject o = getItem(position);

      // create a new view
      View v;
      if (convertView == null || newItemView) {
         v = inflater.inflate(YOUR_ITEM_LAYOUT_VIEW_ID, parent, false);
      } else {
         v = convertView;
      }

      // populate the view
      // use v.findViewById() to locate your layout items and then
      // set a value from the JSONObject that you obtained above

      return view;
   }
}

上面的代码可能无法直接编译(并且不包含任何错误检查),因为我只是在这里内联键入它。。。但希望它能让您了解如何创建一个
ListAdapter
,它可以接受
JSONArray

“无法填充listview”是什么意思?你做了什么?我已经能够得到静态内容的列表视图,就像这样。但是我想要一个动态的内容,我沮丧地删除了当前的文件。。你可以引导pl,包括布局文件来看这个例子吗?我从php和mysqwl获得json数组,如果我有10条名称和地址记录,那么我得到10个数组,但我不能继续