日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/1 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android listview 开发,android开发之ListView实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

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"/>

總結

以上是生活随笔為你收集整理的android listview 开发,android开发之ListView实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。