06_Android中ArrayAdapter的使用

简介: 1 目标界面 2 编写AndroidManifest.xml文件 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"


1 目标界面

2 编写AndroidManifest.xml文件

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.itheima28.arrayadapterdemo"

    android:versionCode="1"

    android:versionName="1.0" >

 

    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="19" />

 

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.itheima28.arrayadapterdemo.MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

</manifest>

3 编写布局文件activity_main.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"

    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.itheima28.arrayadapterdemo.MainActivity$PlaceholderFragment" >

 

    <ListView

        android:id="@+id/listview"

        android:layout_width="match_parent"

        android:layout_height="match_parent"/>

 

</RelativeLayout>

4 编写代码

package com.itheima28.arrayadapterdemo;

 

import android.app.Activity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.ListView;

 

/**

 * ArrayAdapter的使用

 * @author toto

 *

 */

public class MainActivity extends Activity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

      

       ListView mListView = (ListView) findViewById(R.id.listview);

       String[] textArray = {"功能1","功能2","功能3","功能4","功能5","功能6","功能7","功能8"};

      

       /**

        * 定义数据适配器

        */

       ArrayAdapter<String> adapter = new ArrayAdapter<String>(

              this,

              android.R.layout.simple_list_item_1,

              textArray);

       mListView.setAdapter(adapter);

    }

}

 

目录
相关文章
|
XML Android开发 数据格式
【安卓开发】ArrayAdapter requires the resource ID to be a TextView
【安卓开发】ArrayAdapter requires the resource ID to be a TextView
81 0
【安卓开发】ArrayAdapter requires the resource ID to be a TextView
|
Android开发 容器 数据格式
|
XML Android开发 数据格式
Android零基础入门第40节:自定义ArrayAdapter
原文:Android零基础入门第40节:自定义ArrayAdapter    ListView用起来还是比较简单的,也是Android应用程序中最重要的一个组件,但其他ListView可以随你所愿,能够完成很多想要的精美列表,而这正是我们接下来要学习的内容。
1469 0
|
Android开发
Android Spinner的ArrayAdapter和SpinnerAdapter注意事项
Android Spinner的ArrayAdapter和SpinnerAdapter注意事项 如图所示: 代码: package com.
1266 0
|
XML Android开发 数据格式
安卓开发_浅谈ListView(ArrayAdapter数组适配器)
列表视图(ListView)以垂直的形式列出需要显示的列表项。   实现过程:新建适配器->添加数据源到适配器->视图加载适配器   在安卓中,有两种方法可以在屏幕中添加列表视图 1、直接用ListView组件创建 2、让Activity继承ListActivity实现   一、xm...
980 0
|
XML Android开发 数据格式
我的Android进阶之旅------&gt;Android ListView 应用解析(使用ArrayAdapter,SimpleAdapter和SimpleCursorAdapter适配器)
在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示。抽空把对ListView的使用做了整理,并写了个小例子,如下图。
931 0