android listview 开发,android开发之ListView实现

今天又初步学习了一下ListView控件,看看效果如下:

0818b9ca8b590ca3270a3433284dd417.png

LisViewActivity.java源码:

package com.jinhoward.UI_listview;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.os.Bundle;

import android.app.Activity;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.Toast;

public class LisViewActivity extends Activity {

ListView listView=null;

Toast toast;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_lis_view);

listView =(ListView)findViewById(R.id.infolistview);

//生成动态数组,加入数据 ,添加的信息有string,也有int类型(图片id),所以用Map

List> list = new ArrayList>();

//一个map相当于listview的一行.

Map map = new HashMap();

map.put("name", "系统信息");

map.put("notes", "系统版本,运营商及其系统信息.");

map.put("img", R.drawable.system);//图片资源的id

list.add(map);

map = new HashMap();

map.put("name", "硬件信息");

map.put("notes", "CPU,硬盘,内存等硬件信息.");

map.put("img", R.drawable.hardware);

list.add(map);

map = new HashMap();

map.put("name", "软件信息");

map.put("notes", "已经安装的软件信息.");

map.put("img", R.drawable.software);

list.add(map);

map = new HashMap();

map.put("name", "运行时信息");

map.put("notes", "运行时的信息.");

map.put("img", R.drawable.running);

list.add(map);

map = new HashMap();

map.put("name", "文件浏览器");

map.put("notes", "文件系统.");

map.put("img", R.drawable.file_explorer);

list.add(map);

//生成适配器的Item和动态数组对应的元素

SimpleAdapter mySimpleAdapter = new SimpleAdapter(this, list, R.layout.item_row,

new String[] { "name", "notes", "img" }, new int[] { R.id.name,

R.id.notes, R.id.img });

//设置适配器

listView.setAdapter(mySimpleAdapter);

//设置监听器

listView.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView> arg0, View arg1, int arg2,

long arg3) {

// TODO Auto-generated method stub

Toast.makeText(LisViewActivity.this, "您选择了第"+(arg2+1)+"项", Toast.LENGTH_SHORT).show();

}

});

}

}

activity_lis_view.xml源码:

android:id="@+id/LinearLayout1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#D1EEEE"

>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/infolistview" />

item_row.xml源码:

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/vw1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:layout_width="24dp"

android:layout_margin="4dp"

android:layout_height="24dp"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical">

android:textSize="18sp"

android:textStyle="bold"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/>

android:textSize="12sp"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值