File:MainActivity.java
package com.jiangge.arrayadapterdemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
private static String City[] = {"北京", "上海", "天津", "河北", "山东", "山西", "河南"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.list_view);
listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.text_view, City));
}
}
注:listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.text_view, City)); 每个参数的意义
File: layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
File:layout/list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
</LinearLayout>
项目结构:
效果图:
分享到:
相关推荐
android-pulltorefresh-listview 下拉刷新ListView
028_android UI组件之 ListView和ArrayAdapter,很细致的视频教程,这个可以学哦。
•Android---UI篇---Tab Layout(选项卡布局) ...•Android---UI篇---ListView之ArrayAdapter(列表)---2 • •Android---UI篇---ListView之SimpleCursorAdapter(列表)---3 • •Android---UI篇---Menu(菜单)
android-world-of-listview-android
2-android-pulltorefresh-listview 下拉刷新ListView.zip
Android-react-native-timeline-listview.zip,React本机应用程序的时间线组件,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
android-pro-listview.7z
android-custom-listview.7z
19Android-16-listviewBaseAdapter.mp4
19Android-15-listviewArray.mp4
react-native-sortable-listview, ListView的拖放功能包装,用于响应本机 react-native-sortable-listviewListView的拖放功能包装,用于响应本机。 拖动时允许拖放自动滚动行。将它添加到你的项目中运行 npm install...
Android自学笔记-11-listview简单例子
Android--开发--ListView上下翻页效果
Android--开发-- ListView下拉刷新 Demo
21.[开源][安卓][拖拽]drag-sort-listview-master DragSortListView(DSLV)是Android ListView的一个扩展,支持拖拽排序和左右滑动删除功能。重写了TouchInterceptor(TI)类来提供更加优美的拖拽动画效果。 DSLV...
Android-PullToRefresh支持ListView、GridView、ScrollView、WebView等.可以直接导入eclipse使用。在自己的项目中的使用的时候add as library就行了
drag-sort-listview是一个支持拖拽排序和左右滑动删除功能的自定义ListView.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
It works in all version of Android and it's very easy to adapt to your project. How to use with Gradle Simply add the repository to your build.gradle file: repositories { jcenter() maven { url '...
Android--开发--ListView 中的item随意拖动
Android开发笔记---ListView