zoukankan      html  css  js  c++  java
  • android 实现一个简单纯文本的ListView

    思维线路:

    1.创建一个ListViewActivity,LinearLayout布局里写了一个ListView布局

    2.创建一个TextView布局给ArrayAdapter适配器使用

    3.将TextView布局和数据导入适配器ArrayAdapter

    3.将ArrayAdapter适配好的内容导入ListView布局

    代码如下:

    ListViewActivity 的布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/SimpleListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></ListView>
    
    </LinearLayout>
    

    TextView 的布局:

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ListTextView"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_marginLeft="20dp"
        android:text="内容"
        android:textSize="50dp">
    
    
    </TextView>

    onCreate实现代码:

    package com.example.prize.mylistviewdemoapp;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    public class SimpleListView extends AppCompatActivity {
        private String [] data ={"苹果","橘子","芒果","香蕉","柠檬","火龙果","西瓜","李子",
                "芭乐","石榴","葡萄","荔枝","圣女果","杨梅","柿子","山竹","杨桃","雪梨","猕猴桃","榴莲"
                ,"枇杷","樱桃","柚子","水蜜桃","桑葚","莲雾"};
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_simple_list_view);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(SimpleListView.this,R.layout.list_layout,data);//适配器
            ListView listView = (ListView) findViewById(R.id.SimpleListView); //找到ListView布局
            listView.setAdapter(adapter); //导入
        }
    }

    实现效果图:


  • 相关阅读:
    Rman备份及不完全恢复操作
    win2003系统同步Linux ntp server批处理
    ntp服务器搭建
    notepad++调用python3中文乱码
    10G安装DataGuard
    oracle安装配置
    python之路(14)进程
    python之路(13)线程
    python之路(12)网络编程
    python之路(11)描述符
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/9708636.html
Copyright © 2011-2022 走看看