5.乐学成语-----------显示动物类成语列表
来源:互联网 发布:查看电脑的mac地址 编辑:程序博客网 时间:2024/04/28 05:28
1.在layout下新建activity_animal.xml文件,代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_animal" android:orientation="vertical" > <ListView android:id="@+id/lvAnimalList" android:layout_width="match_parent" android:layout_height="wrap_content" android:layoutAnimation="@anim/anim_layout_listview" android:listSelector="#00000000"></ListView></LinearLayout>2.在layout目录下新建animal_item.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" android:padding="10dp"> <TextView android:id="@+id/tvName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:gravity="center" android:text="助人为乐" android:textAppearance="?android:attr/textAppearanceLarge"/> <ImageButton android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:layout_alignParentRight="true" android:layout_alignTop="@+id/tvName" android:src="@drawable/btnsave"/></RelativeLayout>3.新建类AnimalAdapter,代码如下:
public class AnimalAdapter extends ArrayAdapter<Animal>{ private int resourceld; private Context context;public AnimalAdapter(Context context, int resource,List<Animal>objects) {super(context, resource,objects);this.context=context; resourceld = resource;// TODO Auto-generated constructor stub} public View getView(int position,View convertView,ViewGroup parent){final Animal animal=getItem(position);//获取当前项的Animal实例View view;ViewHolder viewHolder;if(convertView ==null){view=LayoutInflater.from(getContext()).inflate(resourceld, null); viewHolder=new ViewHolder(); viewHolder.tvName=(TextView)view.findViewById(R.id.tvName); viewHolder.btnSave=(ImageButton)view.findViewById(R.id.btnSave); viewHolder.btnSave.setFocusable(false); viewHolder.btnSave.setFocusableInTouchMode(false); viewHolder.btnSave.setOnClickListener(new OnClickListener(){ public void onClick(View view){ Toast.makeText(context, "你要收藏"+animal.getName()+"吗",Toast.LENGTH_SHORT ).show(); } }); view.setTag(viewHolder);}else{view=convertView;viewHolder=(ViewHolder)view.getTag();}viewHolder.tvName.setText(animal.getName()); return view; } class ViewHolder{ TextView tvName; ImageButton btnSave; }}
结果图如下:
0 0
- 5.乐学成语-----------显示动物类成语列表
- 乐学成语——显示所有动物类成语的列表
- 乐学成语——显示所有动物类成语的列表
- 乐学成语实现之四:显示所有动物类成语的列表
- 综合项目之乐学成语(显示所有动物类成语的列表)
- 2.乐学成语-------------编写动物类
- 个人完成案例之乐学成语(显示所有动物类成语的列表和每条成语的详细信息)
- 乐学成语(成语分类列表显示)
- 4.乐学成语----------显示学习列表
- 乐学成语——显示学习列表
- 乐学成语——显示学习列表
- 乐学成语——显示每个成语的详细信息
- 6.乐学成语----------显示每条成语的详细信息
- 3.乐学成语----------显示主界面
- HappyIdiom之六(2)点击动物类列表中的每一项以对话框的形式显示该成语的详细信息
- 乐学成语
- 乐学成语
- 乐学成语
- 关于回调函数的理解
- 表字段名和实体类属性名不一致的处理
- ListView的position的保持
- windows下安装oracle11g
- Tomcat探秘(5):tomcat关闭过程详述
- 5.乐学成语-----------显示动物类成语列表
- Windows 7下硬盘安装Ubuntu 13.04图文教程
- JS多物体运动
- ListView的用法 - 第一行代码—android学习笔记
- 简单的启程,从这里开始
- The Triangle(poj1163)
- Qt 出现“undefined reference to `vtable for”原因总结
- PIC单片机之硬件仿真的配置字问题
- 第一课、redis的介绍和安装部署