zoukankan      html  css  js  c++  java
  • ListView的简单用法

     1 package com.example.zhangmeng.listview;
     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     private String [] data={"red","green","blue","black","white"};
    10 
    11     @Override
    12     protected void onCreate(Bundle savedInstanceState) {
    13         super.onCreate(savedInstanceState);
    14         setContentView(R.layout.activity_main);
    15 
    16 
    17         ArrayAdapter<String> adapter=new ArrayAdapter<>(MainActivity.this,android.R.layout.simple_list_item_1,data);
    18         ListView listView=(ListView) findViewById(R.id.lv);
    19         listView.setAdapter(adapter);
    20     }
    21 }
     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="com.example.zhangmeng.listview.MainActivity">
    11 
    12     <ListView
    13         android:id="@+id/lv"
    14         android:layout_width="wrap_content"
    15         android:layout_height="wrap_content"
    16         />
    17 </RelativeLayout>
  • 相关阅读:
    十四、内部类
    十三、模板设计模式
    十二、面向对象之多态
    三、泛型
    Spring Security学习笔记
    Maven构建web项目在Eclipse中部署的几种方法
    spring如何实现定时任务
    安装jar包到本地仓库
    使用java对pdf转成tiff文件
    word文档转pdf解决修订问题
  • 原文地址:https://www.cnblogs.com/WebGiant/p/5808347.html
Copyright © 2011-2022 走看看