那些复杂的列表总要弄个清楚——(四)激动人心的BaseAdapter之二
来源:互联网 发布:c windows syswow64 编辑:程序博客网 时间:2024/06/03 12:14
与“激动人心的BaseAdapter之一”相似
只不过这次的列表项填充方式有所不同,比上一个复杂一些些
效果图:
还是以空格拆分
第一个布局文件(主布局):
<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="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.arial.listview4.MainActivity" android:orientation="vertical"> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dp" android:dividerHeight="2dp"></ListView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/et" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"/> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textSize="18sp" android:text="空格拆分"/> </LinearLayout> </LinearLayout>
还有一个单独的列表项的布局single.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="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/img" android:layout_width="60dp" android:layout_height="60dp" android:scaleType="center"/> <TextView android:id="@+id/tv" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textSize="20sp"/></LinearLayout>
代码:
public class MainActivity extends Activity {ListView lv;EditText et;Button btn;BaseAdapter adapter;String[] ss = {};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);lv = (ListView)findViewById(R.id.lv);et = (EditText)findViewById(R.id.et);btn = (Button)findViewById(R.id.btn);adapter = new BaseAdapter() {@Overridepublic View getView(int arg0, View arg1, ViewGroup arg2) {// TODO Auto-generated method stubView v = LayoutInflater.from(MainActivity.this).inflate(R.layout.single, null);ImageView img = (ImageView)v.findViewById(R.id.img);TextView tv = (TextView)v.findViewById(R.id.tv);img.setBackgroundResource(R.drawable.pic);tv.setText(ss[arg0]);return v;}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn null;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn ss.length;}};btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubss = et.getText().toString().split(" ");adapter.notifyDataSetChanged();}});lv.setAdapter(adapter);}
关于xml布局文件转换成view类型的方法,借鉴:
http://blog.csdn.net/u013424496/article/details/51580016
就酱。
阅读全文
0 0
- 那些复杂的列表总要弄个清楚——(四)激动人心的BaseAdapter之二
- 那些复杂的列表总要弄个清楚——(三)激动人心的BaseAdapter之一
- 那些复杂的列表总要弄个清楚——(二)用SimpleAdapter做适配器
- 那些复杂的列表总要弄个清楚——(一)ListView动态添加项
- 你可记得,那些激动人心的时刻?
- ListView之BaseAdapter的用法简单案例(四)
- 激动人心的Windows 8之旅 !!!!!!!!
- 新JavaScript库的激动人心之处
- Unity编辑器拓展之二:ReorderableList可重新排序的列表框(复杂使用)
- 不一样的RecyclerView优雅实现复杂列表布局(二)
- 激动人心的一刻
- 激动人心的一刻
- 激动人心的一刻
- 【Android】使用BaseAdapter实现复杂的ListView
- 使用BaseAdapter实现复杂的ListView
- 使用BaseAdapter自定义构建复杂的ListView
- 【Android】使用BaseAdapter实现复杂的ListView
- 构建复杂的应用程序(四)—— 总论
- 【Spring】Spring配置文件
- 学习php的第一个实例--留言簿及管理系统
- CLASSPATH、JAVA_HOME的作用
- App Tune-up Kit工具的安装和操作
- Linux下php添加新扩展
- 那些复杂的列表总要弄个清楚——(四)激动人心的BaseAdapter之二
- 用jQuery实现两个所属关系的select选项选择
- 最近回味SSH框架,发现同事的小bug NoSuchMethod $Proxy.add(), 解决办法和根本原因
- sublime text快捷键列表
- ZeroClipboard2.2.0版本跨浏览器复制(兼解决IE下兼容问题)
- windows下多个git账号配置并且将本地仓库项目推送到远程仓库
- 在Linux下编译php扩展
- Shiro第一篇【Shiro的基础知识、回顾URL拦截】
- 移位运算符