码迷,mamicode.com
首页 > 其他好文 > 详细

ArrayAdapter

时间:2016-05-18 10:25:01      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 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

标签:

原文地址:http://www.cnblogs.com/future-zhenzhen/p/5504120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!