android ListView佈局之三(使用自定義的Adapter繫結資料,通過contextView.setTag繫結資料)有按鈕的ListView
http://blog.csdn.net/chenzheng_java/article/details/6202586
最終結果圖:
程式碼結構示意圖
vlist2.xml程式碼:
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
-
android:layout_height
- <ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="5px"
- />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
-
android:orientation
- >
- <TextView
- android:id="@+id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#FFFFFFFF"
- android:textSize="22px"
- />
- <TextView
- android:id="@+id/info"
-
android:layout_width
- android:layout_height="wrap_content"
- android:textColor="#FFFFFFFF"
- android:textSize="13px"
- />
- </LinearLayout>
- <Button
- android:id="@+id/view_btn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="click me"
- android:gravity="center"
- />
- </LinearLayout>
listView3.java程式碼
- package cn.com.android2.listview;
- import java.util.ArrayList;
- import java.util.HashMap;
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ListView;
- publicclass listView3 extends ListActivity {
- @Override
- publicvoid onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // 獲取虛擬的資料,資料的格式有嚴格的要求哦
- ArrayList<HashMap<String, Object>> data = getData();
- //模仿SimpleAdapter實現的自己的adapter
- MyAdapter adapter = new MyAdapter(this, data);
- /**
- * 有些人很迷糊,我們都知道vlist2.xml相當於儲存一行資料的元件佈局,我們在前邊的程式碼中,都是有一個主佈局檔案main.xml的,
- * 元件佈局檔案是放在主佈局檔案上顯示的,一般程式碼中都是通過setContentView()來指定主佈局檔案的。為何這裡根本就沒有用到
- * ,但是listView還能有一個介面來呈現呢。
- * 讓我們看看setListAdapter在ListActivity中的實現,
- * public void setListAdapter(ListAdapter adapter) {
- synchronized (this) {
- ensureList();
- mAdapter = adapter;
- mList.setAdapter(adapter);
- }
- }
- 裡面呼叫了一個ensureList方法,我們再來看看這個方法:
- private void ensureList() {
- if (mList != null) {
- return;
- }
- setContentView(com.android.internal.R.layout.list_content);
- }
- 現在看到了,這裡有個 setContentView方法,裡面設定了我們的元件在一個android自己提供的介面上顯示。
- 原來,我們的理論還是適用的,只不過ListActivity給我進行了隱藏實現。
- */
- setListAdapter(adapter);
- }
- /**
- * @author chenzheng_java
- * @description 準備一些測試資料
- * @return 一個包含了資料資訊的hashMap集合
- */
- private ArrayList<HashMap<String, Object>> getData(){
- ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String,Object>>();
- for(int i=0;i<10;i++){
- HashMap<String, Object> tempHashMap = new HashMap<String, Object>();
- tempHashMap.put("image", R.drawable.icon);
- tempHashMap.put("title", "標題"+i);
- tempHashMap.put("info", "描述性資訊");
- arrayList.add(tempHashMap);
- }
- return arrayList;
- }
- @Override
- protectedvoid onListItemClick(ListView l, View v, int position, long id) {
- Log.i("輸出資訊",v.toString() );
- }
-
相關推薦
android ListView佈局之三(使用自定義的Adapter繫結資料,通過contextView.setTag繫結資料)有按鈕的ListView
http://blog.csdn.net/chenzheng_java/article/details/6202586 最終結果圖: 程式碼結構示意圖 vlist2.xml程式碼: &
Spring原始碼解析之三(自定義標籤的解析)
自定義標籤的解析 1、概述:通過前面的文章我們分析了預設標籤的解析,我們先回顧下自定義標籤解析所使用的方法 /** * Parse the elements at the root level in the document: * "import", "alias", "bean".
JSP編程專題2之JSP核心三(自定義EL函數和標簽)
自定義el函數 jstl中的el函數 自定義el標簽 自定義帶屬性的el標簽 自定義el遍歷標簽 1、自定義EL函數:a、自定義類,類中的方法使用static修飾符修飾:b、該類以及函數,需要在一個擴展名為.tld(tld,tag library definition,標簽庫定義)的XML
Android學習筆記之為Dialog自定義佈局,並說明空指標問題
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
android中的對話方塊之三:自定義對話方塊
首先看下效果圖 下面講一下具體的實現: 1.修改系統預設的Dialog樣式(風格、主題) 2.自定義Dialog佈局檔案 3.可以自己封裝一個類,繼承自Dialog或者直接使用Dialog類來實現,為了方便以後重複使用,建議自己封裝一個Dialog類 ==
【我的Android進階之旅】自定義ContentProvider
引言 我們知道Android有四大元件,ContentProvider是其中之一,顧名思義:內容提供者。什麼是內容提供者呢?一個抽象類,可以暴露應用的資料給其他應用。應用裡的資料通常說的是資料庫,事實上普通的檔案,甚至是記憶體中的物件,也可以作為內容提供者暴露的
【我的Android進階之旅】自定義控制元件之使用ViewPager實現可以預覽的畫廊效果,並且自定義畫面切換的動畫效果的切換時間
我們來看下效果 在這裡,我們實現的是,一個ViewPager來顯示圖片列表。這裡一個頁面,ViewPage展示了前後的預覽,我們讓預覽頁進行Y軸的壓縮,並設定透明度為0.5f,所有我們看到gif最後,左右兩邊的圖片有點朦朧感。讓預覽頁和主頁面有主從感。我們用分
jieba之sedict(自定義字典)
程式碼:import jieba string = "李小福是創新辦主任也是雲端計算方面的專家" # 精確模式分詞 cut_result = jieba.cut(string) print("===" * 20) print("/".join(cut_result))
Android 環信擴充套件訊息(自定義訊息)
之前整合即時通訊(環信)的時候,需要用到自定義訊息的功能。而在開發過程中遇到了許多的問題,之前工作比較忙,現在有時間了記錄一下。 第一步: 首先,在聊天介面新增一個傳送擴充套件訊息的MenuItem
Linux自動化運維之Cobbler(自定義重裝)
localhost reboot ace koan mirrors 虛擬機 all 更換 epel Cobbler?定義重裝 當現有虛擬機運?出現故障後, 需要進?重裝操作, 可通過koan進?重裝系統 將CentOS6重裝成CentOS7 1.客戶端安裝 koan #
Linux自動化運維之Cobbler(自定義系統安裝)
lin gateway onf ces -a entos 網卡 定義 proc ##Cobbler自定義安裝由於 kickstart 指定某臺服務器使?某個具體的 ks ?件?較復雜,所以引? Cobbler 就變得? 常的簡單。通過物理MAC地址來區分。 Cobbler
Linux自動化運維之Cobbler(自定義倉庫)
之間 成對 aliyun 需要 fig kick emc pos var Cobbler?定義倉庫Cobbler會將指定的repo倉庫裏的.rpm包下載到本地,通過Cobbler安裝的系統會在本地生成對應的.repo文件,裏面的地址內容指向Cobbler的IP地址 實現該
彈窗之三:自定義Dialog
第一步: 給Dialog設定一個風格主題 (基本都是用這個主題)無邊框全透明背景: res/values/styles: <!--自定義dialog背景全透明無邊框theme --> <style name="MyDi
Android 日常封裝之暴力CustomViewDialog自定義對話方塊
import android.app.Dialog; import android.content.Context; import android.support.annotation.LayoutRe
CSS之頁面佈局之三(凝膠布局)
介於流體佈局(Float Layout)和凍結佈局(Frozen Layout)間的就是凝膠布局(Jello Layout) 實現方式:在凍結佈局的基礎上,設定CSS端的margin-left/right為auto 第一步就是實現凍結佈局(請參照前一篇博文《CSS之頁面佈
淺談對Bootstrap的看法之三(提示框和彈出框、滾動監聽、小工具)
1.提示框和彈出框相關說明:提示框和彈出框效果類似。提示框:通過向元素新增 data-toggle="tooltip" 來建立提示框,<a href="#" data-toggle="tooltip" title="我是提示內容!">滑鼠移動到我這</a&g
golang web實戰之三(基於iris框架的 web小應用,數據庫采用 sqlite3 )
golang mys 上傳文件 aliyun size 變量 ima appname all 一、效果:一個圖片應用 1、可上傳圖片到uploads目錄。 2、可瀏覽和評論圖片(用富文本編輯器輸入) 二、梳理一下相關知識: 1、iris框架(模板輸出,session
《第一行程式碼Android》學習總結第三章 自定義佈局與控制元件
1、View是Android中最基本的元件,它可以在螢幕上繪製一塊矩形區域,並在這塊區域內響應各種事件。所有控制元件都直接或間接繼承自View。 2、ViewGroup是一種特殊的View,可以包含很多子View和子ViewGroup,是一個用於放置控制元件和佈局的容器。所有佈局都直接或間
Android ListView分兩列顯示(不用自定義Adapter)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pa
Android ListView的應用(如何去實現ListView控制元件(自定義介面卡))
稀稀拉拉學了有快1年的Android了,但是依然跟剛入門的小白一樣,用到啥學啥,上網查別人的程式碼,然後複製貼上過去,最後什麼都沒學到,現在是深有體會,我希望記錄一些知識點,踏踏實實的走好每一步,希望剛入門的小白能用到。首先Android Studio中有許多系統自帶的空間,