android组件ListView之ArrayAdapter简单使用
来源:互联网 发布:淘宝哪里看信誉评价 编辑:程序博客网 时间:2024/04/30 03:16
ArrayAdapter继承于BaseAdapter,主要用来适配简单数据列表。以下代码为简单使用
activity类
public class MainActivity extends Activity { private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView=(ListView)findViewById(R.id.lv); //初始数据 List<String> list = new ArrayList<>(); for (int i = 0; i < 20; i++) { list.add("android_ArrayAdapter"+i); } /** * ArrayAdapter<>(context, resource, textViewResourceId, objects) * * context:上下文环境,activity * resource:listView列表项xml文件 * textViewResourceId:需要展示数据的列表项id * objects:数据 */ ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.listview_item, R.id.lv_item, list); //给组件设置数据适配器 listView.setAdapter(adapter); }}
主界面activity_main.xml
<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:orientation="vertical" tools:context="com.example.l4.MainActivity" > <ListView android:id="@+id/lv" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ListView></LinearLayout>
列表项listview_item.xml
<RelativeLayout 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" tools:context="com.example.l4.MainActivity" > <TextView android:id="@+id/lv_item" android:layout_width="match_parent" android:layout_height="wrap_content" /></RelativeLayout>
效果
1 0
- android组件ListView之ArrayAdapter简单使用
- android listview组件之ArrayAdapter,SimpleAdapter
- android listview组件之ArrayAdapter,SimpleAdapter
- android listview组件之ArrayAdapter,SimpleAdapter
- android listview组件之ArrayAdapter,SimpleAdapter
- Android实例demo11之listview的简单使用(arrayadapter、simpleadapter)
- Android学习之ListView与ArrayAdapter的简单使用
- android中ListView+ArrayAdapter简单使用
- Android ListView ArrayAdapter 的简单使用
- Android中ListView之ArrayAdapter的使用
- android ListView之——ArrayAdapter使用
- Android ListView使用ArrayAdapter
- android组件ListView之SimpleAdapter简单使用
- android组件ListView之BaseAdapter简单使用
- Android之ListView详解ArrayAdapter
- ListView之ArrayAdapter的使用
- ListView之ArrayAdapter的使用
- Android UI学习之ListView(使用ArrayAdapter和SimpleAdapter)
- 构造与析构函数在继承中如何调用
- csdn如何转载别人的文章
- 二叉树重建
- 2017.4.20 hanoi双塔问题 思考记录
- Deep Learning(深度学习)学习笔记整理系列之(八)
- android组件ListView之ArrayAdapter简单使用
- spring mvc controller接收请求值及controller之间跳转及传值
- 访问者模式
- CF
- Unity 3D 创建Mesh(二)
- windows部署tomcat项目(5)
- 编写可维护的 JavaScript 笔记 (1-3章)
- 找出字符串的最长不重复子串,输出长度
- C++友元函数和友元类