zoukankan      html  css  js  c++  java
  • Android 给ListView设置Adapter

    Adapter:

    class MyAdapter extends BaseAdapter {
            private List<Person> personList;
    
            public MyAdapter(List<Person> personList) {
                this.personList = personList;
            }
    
            @Override
            public int getCount() {
                return personList.size();
            }
    
            @Override
            public Object getItem(int position) {
                return null;
            }
    
            @Override
            public long getItemId(int position) {
                return 0;
            }
    
            /**
             * 使用打气筒
             */
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Person person  = personList.get(position);
                View view = View.inflate(MainActivity.this, R.layout.list_view, null);
                //在view里面查找
                TextView idTextView = (TextView) view.findViewById(R.id.id);
                //一定要是String类型
                idTextView.setText("ID:"+person.getId()+"");
    
                TextView nameTextView = (TextView) view.findViewById(R.id.name);
                nameTextView.setText(person.getName());
    
                TextView ageTextView = (TextView) view.findViewById(R.id.age);
                ageTextView.setText(person.getAge()+"");
                return view;
            }
  • 相关阅读:
    hdu 6010 Daylight Saving Time
    hdu 5999 The Third Cup is Free
    2011 USP Try-outs F. Auction of Services
    1449 砝码称重
    hdu 6205 card card card
    hdu 6201 transaction transaction transaction
    Codeforces 828D
    Codeforces Round #434 D
    zoj
    Codeforces Round #434 C
  • 原文地址:https://www.cnblogs.com/wuyou/p/3423213.html
Copyright © 2011-2022 走看看