小编Chi*_*ala的帖子

Android ArrayAdapter和JSONArray

我是Android开发的新手.

考虑到JSON Carrier与XML相比的轻巧性,我纯粹喜欢使用JSON Objects和Arrays作为我的简单应用程序.

我对ArrayAdapter提出了挑战,要求填充ListView.

这就是我如何克服并需要你的建议.

Extend the Adaptor class.
Run Code Online (Sandbox Code Playgroud)

然后将JSONArray传递给构造函数.
这里构造函数使用设置JSONArray长度的虚拟 String数组调用super .
将构造函数参数存储在类中以供进一步使用.

public myAdaptor(Context context, int resource, JSONArray array)
{
    super(context, resource, new String[array.length()]);
    // Store in the local varialbles to the adapter class.
    this.context = context;
    this.resource = resource;
    this.profiles = objects;
}
Run Code Online (Sandbox Code Playgroud)

getView()会做的工作获取从JSONArray一个JSONObjects建立视图.

public View getView(int position, View convertView, ViewGroup parent)
{
    View view;
    if (convertView == null)
    {
        LayoutInflater inflater = (LayoutInflater) 
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(resource, parent, false);
    } …
Run Code Online (Sandbox Code Playgroud)

arrays android listview jsonobject

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

arrays ×1

jsonobject ×1

listview ×1