创建listview的布局界面必须通过什么属性才能使数据显示在界面上
1个回答
展开全部
Android加载list列表数据主要通Adapter实现用显示列表控件: Listview GridView ExpandListview 显示具体数据需要通Adapter实现Android目前4种Adapter: ArrayAdapter SimpleAdapter SimpleCursorAdapter BaseAdapter ( 自定义Adapter) 具体操作步骤 ( 自定义Adapter例): xml定义Listview布局代码通ID找Listview控件构建Adapter象新建类继承自BaseAdapter重写四具体代码构造适配器设置Listviewadapter象新建适配器界面即显示数据数据变需要调用adapternotifyDataSetChanged即刷新界面 package com.beryl.gougou; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import java.util.List; /** * Created by yt on 16/11/14. */ public class MyAdapter extends BaseAdapter { private List datalist; private LayoutInflater inflater; public MyAdapter(Context context ,List datalist){ this.datalist = datalist; inflater = LayoutInflater.from(context); } @Override public int getCount() { return datalist.size(); } @Override public Object getItem(int position) { return datalist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { //处参考网view缓存机制,示例demo说明 return null; } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询