zoukankan      html  css  js  c++  java
  • Android ListView使用(非原创)

    1.ListView:它以列表的形式展示具体要显示的内容,并且能够根据数据的长度自适应屏幕显示

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    	
        <ListView
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
    
    </LinearLayout>
    

    2.使用ListView的步骤:

      2.1根据ID获取ListView对象,ListView lv = (ListView) findViewById(R.id.lv);

      2.2准备适配器,Adapter

    class MyAdapter extends BaseAdapter{
    
    		@Override
    		public int getCount() {
    			// TODO Auto-generated method stub
    			return list.size();
    		}
    
    		@Override
    		public Object getItem(int position) {
    			// TODO Auto-generated method stub
    			return null;
    		}
    
    		@Override
    		public long getItemId(int position) {
    			// TODO Auto-generated method stub
    			return 0;
    		}
    
    		@Override
    		public View getView(int position, View convertView, ViewGroup parent) {
    			// TODO Auto-generated method stub
    			Emp e = list.get(position);
    			View v = View.inflate(MainActivity.this,R.layout.item_listview,null);
    			TextView tv_name = (TextView) v.findViewById(R.id.tv_name);
    			tv_name.setText(e.getName());
    			TextView tv_salary = (TextView) v.findViewById(R.id.tv_salary);
    			tv_salary.setText(e.getSalary());
    			TextView tv_phone = (TextView) v.findViewById(R.id.tv_phone);
    			tv_phone.setText(e.getPhone());
    			return v;
    		}
    	}
    

       2.3传入适配器对象,lv.setAdapter(adapter);

     

  • 相关阅读:
    Redis事务和锁
    11/6笔记 补充(Redis持久化,RDB&&AOF)
    11/6随笔
    Redis 安装教程
    Redis通用指令和第一个Jedis程序的实现
    Redis学习第二天
    SpringBoot学习笔记
    1000行代码手写服务器
    log4j创建实例异常
    寒假阅读人月神话3
  • 原文地址:https://www.cnblogs.com/biao2015/p/5070275.html
Copyright © 2011-2022 走看看