• 适配器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

  • 相关阅读:
    oo第二次博客作业
    oo第一次博客作业
    软件工程第3次作业 | 提问回顾与个人总结
    软件工程第2次作业 | 结对项目-最长单词链
    软件工程第1次作业 | 第一次阅读
    软件工程第0次作业 | 热身
    OO第四次博客作业
    OO第三次博客作业
    OO第二次博客作业
    OO第一次博客作业
  • 原文地址:https://www.cnblogs.com/wangchuanqi/p/5501951.html
Copyright © 2020-2023  润新知