編輯:關於Android編程
此demo實現了列表ListView和可擴展列表ExpandableListView。
ListViewActivity:
package fk.androiddemo_16; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; //1,繼承ListActivity //2,Activity布局文件中添加ListView控件 //3,為列表創建布局文件 public class MyListActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); ListExpandableListViewActivity:
package fk.androiddemo_16; import android.app.ExpandableListActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; import android.widget.TextView; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; //1,繼承ExpandableListActivity //2,Activity布局文件中添加ExpandableListView控件 //3,分別為group和child列表創建布局文件 public class MyExpendableListActivity extends ExpandableListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_expendable_list); //存放組列表,每個組都要有一個對應的子列表,否則出錯 List
控制台輸出結果:
10-04 09:56:22.073 2794-2840/fk.androiddemo_16 D/OpenGLRenderer: endAllActiveAnimators on 0x7ffedc87d800 (RippleDrawable) with handle 0x7ffedbe326c0
10-04 09:56:24.273 2794-2794/fk.androiddemo_16 I/System.out: Position:0 ID:0 Content:liming1.mp3
10-04 09:56:25.948 2794-2794/fk.androiddemo_16 I/System.out: Position:1 ID:1 Content:liming2.mp3
10-04 09:56:27.413 2794-2794/fk.androiddemo_16 I/System.out: Position:2 ID:2 Content:liming3.mp3
10-04 09:56:43.984 2794-2840/fk.androiddemo_16 D/OpenGLRenderer: endAllActiveAnimators on 0x7ffedc87dc00 (RippleDrawable) with handle 0x7ffedba5c240
10-04 09:56:50.848 2794-2794/fk.androiddemo_16 I/System.out: child1Date1
10-04 09:56:50.848 2794-2794/fk.androiddemo_16 I/System.out: groupPosition:0 childPosition:0 id:0
10-04 09:56:52.850 2794-2794/fk.androiddemo_16 I/System.out: child1Date2
10-04 09:56:52.850 2794-2794/fk.androiddemo_16 I/System.out: groupPosition:0 childPosition:1 id:1
10-04 09:56:57.696 2794-2794/fk.androiddemo_16 I/System.out: child2Date1
10-04 09:56:57.696 2794-2794/fk.androiddemo_16 I/System.out: groupPosition:1 childPosition:0 id:0
10-04 09:57:00.852 2794-2794/fk.androiddemo_16 I/System.out: child2Date2
10-04 09:57:00.853 2794-2794/fk.androiddemo_16 I/System.out: groupPosition:1 childPosition:1 id:1
本人所有文章首先發布於個人博客,歡迎關注,地址:http://blog.isming.me 昨天正式發布了android 5,同時android developer
自定義view練習 仿支付寶芝麻信用的儀表盤對比圖:首先是自定義一些屬性,可自己再添加,挺基礎的,上代碼<?xml version=1.0 encoding
一 相關下載(1) java JDK下載:進入該網頁: http://java.sun.com/javase/downloads/index.jsp (或者
事件分發android事件處理的時候 會根據事件發生的坐標,從父容器一直慢慢的發送到相關的所有的view 因此當都不處理的時候 事件傳遞的流程圖dispatchTouch