Android Listview数据显示

正常充气:

        lvStudents = (ListView) findViewById(R.id.lvStudent);
        adapter = new StudentAdapter(this, biz.getStudents());
        lvStudents.setAdapter(adapter);

        lvData = (ListView) findViewById(R.id.lvData);
        adapter = new ConversationAdapter(this, biz.getConversations());
        lvData.setAdapter(adapter);

特殊充气:

//CallLogListAdapter getView()方法中充气如下:
        if (convertView == null) {
            // 注意是充气是mItemLayoutResId,那就具体是在CallLogFragment中的onCreateView中充气的.
            convertView = mLayoutInflater.inflate(mItemLayoutResId, null);
        }

        //CallLogFragment中具体充气成功如下:
        List<ContactBean> contactListData = new ArrayList<ContactBean>();
        mContactsListAdapter = new ContactsListAdapter(getActivity(),contactListData,      R.layout.contacts_list_item_layout);
        mContactsListView.setAdapter(mContactsListAdapter);

listview显示数据三种方式:

1:changeData

StuMainActivity类中:
        private void setupView() {
        lvStudents = (ListView) findViewById(R.id.lvStudents);
        adapter = new StudentAdapter(this, null);
        lvStudents.setAdapter(adapter);
    }

StudentAdapter类中:
        public void setStudents(ArrayList<Student> students) {
        if (students != null)
            this.students = students;
        else
            this.students = new ArrayList<Student>();
    }
    public StudentAdapter(Context context, ArrayList<Student> students) {
        this.setStudents(students);
        this.inflater = LayoutInflater.from(context);
    }
adapter.changeData(biz.getStudents());

2:util
MainActivity类中:

private void setupView() {
        this.lv1 = (ListView) findViewById(R.id.lv1);
        this.productService = new ProductService();
        List<Product> list = this.productService.findAll();
        this.adapter = new ProductAdapter(list, LayoutInflater.from(this));
        lv1.setAdapter(adapter);
                }

ProductAdapter类中:

public ProductAdapter(List<Product> list,LayoutInflater inflater) {
        this.list = list;
        this.inflater = inflater;
    }

3:application
FSPointActivity类中:

user = MyApplication.getMyApplication().getUser();
    private void setupView() {
        keywords = user.getCustomKeywords();
        adapter = new PointsAdapter(this, keywords);
        gvPoints.setAdapter(adapter);
        }

PointsAdapter类中:

public void setKeywords(ArrayList<CustomKeyword> keywords) {
        if (keywords != null) {
            this.keywords = keywords;
        } else {
            this.keywords = new ArrayList<CustomKeyword>();
        }
    }
    public PointsAdapter(Context context, ArrayList<CustomKeyword> keywords) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.setKeywords(keywords);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值