Android List Adapter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android List Adapter相关的知识,希望对你有一定的参考价值。

技术分享技术分享技术分享技术分享技术分享

 1 package comu.metrox.arrayadapertdemo;
 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 MainActivity extends AppCompatActivity {
 9 
10     @Override
11     protected void onCreate(Bundle savedInstanceState) {
12         super.onCreate(savedInstanceState);
13         setContentView(R.layout.activity_main);
14         ListView list1 = (ListView)findViewById(R.id.listView);
15         ListView list2 = (ListView)findViewById(R.id.listView2);
16         String[] array1 = new String[]{"ios","Android","Windows Mobile 10"};
17         String[] array2 = new String[]{"C#","SQL","Swift","Go"};
18         ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,R.layout.array_item,array1);
19         list1.setAdapter(adapter1);
20     }
21 }
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="wrap_content"
 5     android:textSize="24dp"
 6     android:padding="10px"
 7     android:shadowColor="#f0f"
 8     android:shadowDx="4"
 9     android:shadowDy="4"
10     android:shadowRadius="2"
11     android:id="@+id/textView" />
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout 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="comu.metrox.arrayadapertdemo.MainActivity">
11 
12     <ListView
13         android:layout_width="match_parent"
14         android:layout_height="wrap_content"
15         android:id="@+id/listView"
16         android:divider="#f00"
17         android:dividerHeight="2px" />
18 
19     <ListView
20         android:layout_width="match_parent"
21         android:layout_height="wrap_content"
22         android:id="@+id/listView2"
23         android:dividerHeight="2px"
24         android:divider="#0f0" />
25 </RelativeLayout>

 

以上是关于Android List Adapter的主要内容,如果未能解决你的问题,请参考以下文章

Android List + Adapter 仅显示第一个条目

为啥 recyclerview$adapter 在片段中为空

从 List Adapter Android 中的按钮单击编辑 EditText

Android适配器之ArrayAdapterSimpleAdapter和BaseAdapter的简单用法

如何在android 动态加载插件small

Android RecyclerView Adapter DataBinding - 找不到符号 layoutBindingImpl