适配器1

package com.example.wang.testapp2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TestActivity7 extends AppCompatActivity {

    ListView lv_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test7);

       // ListView lv_1=(ListView)findViewById(R.id.lv_1);
        lv_1=(ListView)findViewById(R.id.lv_1);

        //第一步,数据集合,创建layout文件——array_adapter
        String[] strings={"A1","A2","A3","A4","A5","A6","A7","A8","A9","A1","A2","A3","A4","A5","A6","A7","A8","A9"};

        //第二步,创建Adapter
        ArrayAdapter<String>  arrayAdapter=new ArrayAdapter<String>(this,R.layout.array_adapter,strings);

        //第三步,绑定到ListView
        lv_1.setAdapter(arrayAdapter);
    }
}
java
<?xml version="1.0" encoding="utf-8"?>


    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"/>
array_adapter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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.example.wang.testapp2.TestActivity7">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lv_1"></ListView>
</LinearLayout>
activity_test7

posted @ 2016-05-17 15:52  1011042043  阅读(93)  评论(0编辑  收藏  举报