06_Android中ArrayAdapter的使用
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); ??? } } |
?
總結
以上是生活随笔為你收集整理的06_Android中ArrayAdapter的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新冠紫外线灯消毒时间(紫外线灯消毒时间)
- 下一篇: 07_Android操作sqllite数