listview适配器的编写
2016-01-21 11:43
309 查看
listview适配器arrayAdapter
构造完成只需2在其他地方调用即可
xml文件代码如下
public class Myadapter extends BaseAdapter { /* 构造器可以有多个 */ private int images[]; private String names[],signs[]; public Myadapter(int images[],String names[],String signs[]){ this.names=names; this.images=images; this.signs=signs; } @Override public int getCount() { // TODO Auto-generated method stub return names.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return names[arg0]; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub arg1=LayoutInflater.from(context).inflate(R.layout.list, null) ; TextView name,sign; ImageView image; name=(TextView)arg1.findViewById(R.id.name); sign=(TextView)arg1.findViewById(R.id.sign); image=(ImageView)arg1.findViewById(R.id.image); name.setText(names[arg0]); sign.setText(signs[arg0]); image.setImageResource(images[arg0]); return arg1; } }
构造完成只需2在其他地方调用即可
xml文件代码如下
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/image" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/p_1" /> <TextView android:id="@+id/name" android:layout_height="30dp" android:layout_width="match_parent" android:text="如花" android:layout_toRightOf="@+id/image" android:gravity="center_vertical" /> <TextView android:id="@+id/sign" android:layout_height="30dp" android:layout_width="wrap_content" android:text="......." android:textSize="10dp" android:gravity="center_vertical" android:textColor="#3299cc" android:layout_below="@+id/name" android:layout_toRightOf="@+id/image" /> </RelativeLayout>
相关文章推荐
- Android性能优化典范
- Maven 配置
- 超全!整理常用的iOS第三方资源
- js方法调用
- qt 声音
- httpclient 4.3及以上版本,发送和接收https
- yum install erlang 执行报错
- java反射学习
- 单元测试/集成测试/系统测试的区别
- 认证
- https双向认证(基于程序访问,j2ee和android上皆可用)
- 【HDU】 3127 WHUgirls
- linux下openssl编程
- CC2541之SimpleBLEPeripheral程序流程分析 -- 02.App层初始化
- 修改radio、checkbox、select默认样式的方法
- VC++ UTF-8与GBK格式转换
- 基于Solr的HBase多条件查询测试
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android打包混淆----APP加密防破解 + 重新签名
- 启动hbase 出现问题 没有HRegonServer