Android控件ListView简易使用(使用ArrayAdapter)

1<?xml version="1.0" encoding="utf-8"?> 2 3 <TextView xmlns:android="http://schemas.android.com/apk/res/android" 4 android:id="@+id/tv" 5 android:layout_width="match_parent" 6 android:layout_height="wrap_content" 7 /> 8 9<?xml version="1.0" encoding="utf-8"?> 10<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" 13 android:orientation="horizontal" > 14 15 <ImageView 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:src="@drawable/ic_launcher" /> 19 20 <TextView 21 android:id="@+id/item_tv" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" /> 24 25</LinearLayout> 26 27<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 28 xmlns:tools="http://schemas.android.com/tools" 29 android:layout_width="match_parent" 30 android:layout_height="match_parent" 31 android:paddingBottom="@dimen/activity_vertical_margin" 32 android:paddingLeft="@dimen/activity_horizontal_margin" 33 android:paddingRight="@dimen/activity_horizontal_margin" 34 android:paddingTop="@dimen/activity_vertical_margin" 35 tools:context=".MainActivity" > 36 37 <ListView 38 android:id="@+id/arr_lv" 39 android:layout_width="match_parent" 40 android:layout_height="match_parent"></ListView> 41 42</RelativeLayout>

Activity:

1package com.example.arrayadapter; 2 3import java.util.ArrayList; 4 5import android.os.Bundle; 6import android.app.Activity; 7import android.view.Menu; 8import android.widget.ArrayAdapter; 9import android.widget.ListView; 10 11public class MainActivity extends Activity 12{ 13 14 private String [] names={"功能1","功能2","功能3","功能4","功能5"}; 15 private ArrayList<String> list=new ArrayList<String>(); 16 @Override 17 protected void onCreate(Bundle savedInstanceState) 18 { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 ListView lv=(ListView)findViewById(R.id.arr_lv); 23 //4个参数的构造方法 24 //lv.setAdapter(new ArrayAdapter<String>(this,R.layout.listitem,R.id.item_tv,names)); 25 //3个参数的构造方法 要求布局文件只能有一个textview 26 lv.setAdapter(new ArrayAdapter<String>(this,R.layout.listitem_tv,getData())); 27 } 28 private ArrayList<String> getData() 29 { 30 list.add("180平米的房子"); 31 list.add("一个勤劳漂亮的老婆"); 32 list.add("一辆宝马"); 33 list.add("一个强壮且永不生病的身体"); 34 list.add("一个喜欢的事业"); 35 return list; 36 } 37 @Override 38 public boolean onCreateOptionsMenu(Menu menu) 39 { 40 // Inflate the menu; this adds items to the action bar if it is present. 41 getMenuInflater().inflate(R.menu.main, menu); 42 return true; 43 } 44 45}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )