View(视图)——ListView之ArrayAdapter
Posted 安然罒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了View(视图)——ListView之ArrayAdapter相关的知识,希望对你有一定的参考价值。
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.example.wang.testapp2.TestActivity7" 11 android:orientation="vertical"> 12 13 14 <ListView 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content" 17 android:id="@+id/lv_1" /> 18 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <TextView xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:textSize="20sp" 6 android:paddingTop="10dp" 7 android:paddingBottom="10dp"/>
1 package com.example.wang.testapp2; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.widget.ArrayAdapter; 6 import android.widget.ListView; 7 8 public class TestActivity7 extends AppCompatActivity { 9 10 ListView lv_1; 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.activity_test7); 16 17 ListView lv_1=(ListView)findViewById(R.id.lv_1); 18 19 //1.数据集合 Layout 20 String [] strings={"A1","A2","A3","A4","A5","A6","A7","A8","A9", 21 "A1","A2","A3","A4","A5","A6","A7","A8","A9"}; 22 23 //2.创建Adapter 24 ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,R.layout.array_adapter,strings); 25 26 //3.绑定到ListView 27 lv_1.setAdapter(arrayAdapter); 28 29 } 30 }
以上是关于View(视图)——ListView之ArrayAdapter的主要内容,如果未能解决你的问题,请参考以下文章
View(视图)——ListView之ArrayAdapter
View(视图)——ListView之BaseAdapter
View(视图)——ListView之BaseAdapter和SimpleCursorAdapter以及网格视图代码视图
View(视图)——ListView之ArrayAdapter和SimpleAdapter文集