ArrayAdapter
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.hanqi.testapp2.TestActivity7"> 11 12 <ListView 13 android:layout_width="match_parent" 14 android:layout_height="match_parent" 15 android:id="@+id/lv_1"></ListView> 16 17 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 3 4 <TextView xmlns:android="http://schemas.android.com/apk/res/android" 5 android:layout_width="match_parent" 6 android:layout_height="wrap_content" 7 android:textSize="20sp" 8 android:paddingTop="10dp" 9 android:paddingBottom="10dp" />
1 package com.hanqi.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 }
以上是关于ArrayAdapter的主要内容,如果未能解决你的问题,请参考以下文章
片段中的 Android ListView ArrayAdapter 不起作用
ArrayAdapter 要求资源 ID 为 TextView,ListView 无法转换为 TextView
如何在 ArrayAdapter 中调用 getSupportFragmentManager()
ArrayAdapter.NotifyDataSetChanged() 不工作?