Ⅰ 如何離線安裝android sdk
打開AndroidSDKManager可見大致分為三類下載:
第一個分類tools
第二個分類為各版本api
第三個分為Extras
從這三個類別中各選擇一個並開始下載,此時打開右下角的查看日誌按鈕(紅色手右邊的那個按鈕)可獲取讀取xml文件日誌。
(如提示無法下載成功,可能所處網路無法正常訪問下載地址,可在Tool>Options中勾選Forcehttps://...)
從認真查看日誌文件,發現規律如下:
先載入一個xml文件,解析該xml文件,再從該xml文件中獲取對應分類的文件的版本信息。
逐一打開這幾個xml文件,發現就是描述各分類文件的版本信息的,此時我們可從xml文件查看各文件名,只需該文件名填入到這個下載地址即可完成下載:
https://dl-ssl.google.com/android/repository/******.zip(後面這個******.zip是根據你需要下載的文件進行對應填充)。
系統鏡像地址前綴:
http://dl-ssl.google.com/android/repository/sysimg_armv7a-17_r02.zip
http://dl-ssl.google.com/android/repository/sys-img/mips/sysimg_mips-17_r01.zip
http://dl-ssl.google.com/android/repository/sys-img/x86/sysimg_x86-17_r01.zip
日誌結構大致如下:
Fetchinghttps://dl-ssl.google.com/android/repository/addons_list-2.xml
ValidateXML
ParseXML
FetchedAdd-onsListsuccessfully
FetchingURL:https://dl-ssl.google.com/android/repository/repository-8.xml
ValidateXML:https://dl-ssl.google.com/android/repository/repository-8.xml
ParseXML:https://dl-ssl.google.com/android/repository/repository-8.xml
FoundSDKPlatformAndroid1.1,API2,revision1(Obsolete)
FoundSDKPlatformAndroid1.5,API3,revision4
FoundSDKPlatformAndroid1.6,API4,revision3
...略去....
ParseXML:https://dl-ssl.google.com/android/repository/addon.xml
FoundGoogleAPIs,AndroidAPI3,revision3
FoundGoogleAPIs,AndroidAPI4,revision2
FoundGoogleAPIs,AndroidAPI5,revision1(Obsolete)
...略去......
FetchingURL:https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
ValidateXML:https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
ParseXML:https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
(HAXM),revision3
...略去......
ParseXML:https://dl-ssl.google.com/android/repository/sys-img/mips/sys-img.xml
FoundMIPSSystemImage,AndroidAPI15,revision1
FoundMIPSSystemImage,AndroidAPI16,revision4
FoundMIPSSystemImage,AndroidAPI17,revision1
...略去......
ParseXML:https://dl-ssl.google.com/android/repository/sys-img/x86/sys-img.xml
FoundIntelx86AtomSystemImage,AndroidAPI10,revision2
FoundIntelx86AtomSystemImage,AndroidAPI15,revision1
FoundIntelx86AtomSystemImage,AndroidAPI16,revision1
FoundIntelx86AtomSystemImage,AndroidAPI17,revision1
FoundIntelx86AtomSystemImage,AndroidAPI18,revision1
...略去......
Ⅱ Android ArrayList數組
java">List<JSONObject>b=newArrayList<JSONObject>();
for(JSONObjectobj:chidlMenu){
b.add(JSONObject.fromObject("{Instry:"+obj.get("Instry").toString()+"}"));
}
對不起,剛剛測試沒通過.現在這個可以了.
Ⅲ android 中listview 的用法
1.在xml裡面定義一個ListView,這個xml是一個activity的layout文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_width="wrap_content" //定義一個listView
android:layout_height="wrap_content"
android:id="@+id/ListView01"
/>
</LinearLayout>
2.定義ListView每個條目的Layout,比如命名為listview_item.xml,用RelativeLayout實現:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip"
android:paddingLeft="12dip"
android:paddingRight="12dip">
<ImageView
android:paddingTop="12dip"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
/>
<TextView
android:text="TextView01"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="fill_parent"
android:id="@+id/ItemTitle"
/>
<TextView
android:text="TextView02"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/ItemTitle"
android:id="@+id/ItemText"
/>
</RelativeLayout>
3.在Activity裡面調用和加入Listener,具體見注釋:
package com.ray.test;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class TestListView extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//綁定Layout裡面的ListView
ListView list = (ListView) findViewById(R.id.ListView01);
//生成動態數組,加入數據
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.checked);//圖像資源的ID
map.put("ItemTitle", "Level "+i);
map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves! ");
listItem.add(map);
}
//生成適配器的Item和動態數組對應的元素,這里用SimpleAdapter作為ListView的數據源
//如果條目布局比較復雜,可以繼承BaseAdapter來定義自己的數據源。
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//數據源
R.layout.list_items,//ListItem的XML實現
//動態數組與ImageItem對應的子項
new String[] {"ItemImage","ItemTitle", "ItemText"},
//ImageItem的XML文件裡面的一個ImageView,兩個TextView ID
new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}
);
//添加並且顯示
list.setAdapter(listItemAdapter);
//添加點擊
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
setTitle("點擊第"+arg2+"個項目");
}
});
//添加長按點擊
list.(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
menu.setHeaderTitle("長按菜單-ContextMenu");
menu.add(0, 0, 0, "彈出長按菜單0");
menu.add(0, 1, 0, "彈出長按菜單1");
}
});
}
//長按菜單響應函數
@Override
public boolean onContextItemSelected(MenuItem item) {
setTitle("點擊了長按菜單裡面的第"+item.getItemId()+"個項目");
return super.onContextItemSelected(item);
}
}
Ⅳ 有關android中ArrayList初始化和實例化的問題
要想讓List<User> userList;只初始化一次,創建一個全局的List。在應用程序運行過程中始終只有一個。
具體做法
寫一個自定義的類繼承Application類(該類是一個全局類整個應用程序中只會初始化一次,所以裡面的屬性也只會初始化一次),然後在自定義的Application類中初始化List。
用的時候取出來就行了。
如果還不明白可以在網上搜一下Application。上面有詳細的講解。
希望對你有所幫助。
Ⅳ 如何在Android開發中動態載入的list列表數據
Android中載入list列表數據主要是通過Adapter實現,可用顯示列表的控制項如下:
Listview
GridView
ExpandListview
顯示具體的數據需要通過Adapter實現,Android目前有4種Adapter:
ArrayAdapter
SimpleAdapter
SimpleCursorAdapter
BaseAdapter ( 自定義Adapter)
具體操作步驟 ( 以自定義Adapter為例):
在xml中定義Listview布局
在代碼中通過ID找到Listview控制項
構建Adapter對象,新建一個類繼承自BaseAdapter,重寫它的四個方法,具體如下代碼
構造好適配器後設置Listview的adapter對象為新建的適配器,界面即可顯示數據
在數據變動的地方,只需要調用adapter的notifyDataSetChanged方法即可刷新界面
packagecom.beryl.gougou;
importandroid.content.Context;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseAdapter;
importjava.util.List;
/**
*Createdbyyton16/11/14.
*/
{
privateList<String>datalist;
privateLayoutInflaterinflater;
publicMyAdapter(Contextcontext,List<String>datalist){
this.datalist=datalist;
inflater=LayoutInflater.from(context);
}
@Override
publicintgetCount(){
returndatalist.size();
}
@Override
publicObjectgetItem(intposition){
returndatalist.get(position);
}
@Override
publiclonggetItemId(intposition){
returnposition;
}
@Override
publicViewgetView(intposition,ViewconvertView,ViewGroupparent){
//此處參考網上的view緩存機制,示例demo不多說明
returnnull;
}
}
Ⅵ Android 中ArrayList和LinkedList有什麼區別
ArrayList採用的是數組形式來保存對象的,這種方式將對象放在連續的位置中,所以最大的缺點就是插入刪除時非常麻煩
LinkedList採用的將對象存放在獨立的空間中,而且在每個空間中還保存下一個鏈接的索引但是缺點就是查找非常麻煩要叢第一個索引開始
Hashtable和HashMap類有三個重要的不同之處。第一個不同主要是歷史原因。Hashtable是基於陳舊的Dictionary類的,HashMap是Java1.2引進的Map介面的一個實現。
也許最重要的不同是Hashtable的方法是同步的,而HashMap的方法不是。這就意味著,雖然你可以不用採取任何特殊的行為就可以在一個多線程的應用程序中用一個Hashtable,但你必須同樣地為一個HashMap提供外同步。一個方便的方法就是利用Collections類的靜態的synchronizedMap()方法,它創建一個線程安全的Map對象,並把它作為一個封裝的對象來返回。這個對象的方法可以讓你同步訪問潛在的HashMap。這么做的結果就是當你不需要同步時,你不能切斷Hashtable中的同步(比如在一個單線程的應用程序中),而且同步增加了很多處理費用。
第三點不同是,只有HashMap可以讓你將空值作為一個表的條目的key或value。HashMap中只有一條記錄可以是一個空的key,但任意數量的條目可以是空的value。這就是說,如果在表中沒有發現搜索鍵,或者如果發現了搜索鍵,但它是一個空的值,那麼get()將返回null。如果有必要,用containKey()方法來區別這兩種情況。
一些資料建議,當需要同步時,用Hashtable,反之用HashMap。但是,因為在需要時,HashMap可以被同步,HashMap的功能比Hashtable的功能更多,而且它不是基於一個陳舊的類的,所以有人認為,在各種情況下,HashMap都優先於Hashtable。
關於Properties
有時侯,你可能想用一個hashtable來映射key的字元串到value的字元串。DOS、Windows和Unix中的環境字元串就有一些例子,如key的字元串PATH被映射到value的字元串C:WINDOWS;C:WINDOWSSYSTEM。Hashtables是表示這些的一個簡單的方法,但Java提供了另外一種方法。
Java.util.Properties類是Hashtable的一個子類,設計用於Stringkeys和values。Properties對象的用法同Hashtable的用法相象,但是類增加了兩個節省時間的方法,你應該知道。
Store()方法把一個Properties對象的內容以一種可讀的形式保存到一個文件中。Load()方法正好相反,用來讀取文件,並設定Properties對象來包含keys和values。
注意,因為Properties擴展了Hashtable,你可以用超類的put()方法來添加不是String對象的keys和values。這是不可取的。另外,如果你將store()用於一個不包含String對象的Properties對象,store()將失敗。作為put()和get()的替代,你應該用setProperty()和getProperty(),它們用String參數。
Ⅶ android的ListView如何追加數據
實現代碼如下:
package com.app.test01;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.app.adapter.MyWeixinJSON;
import com.app.adapter.MyWeixinList;
/**
* 點擊 追加數據的ListView
* @author 402-9
*
*/
public class ListViewPage extends Activity {
private ListView lv;
private BaseAdapter mJson;
private JSONArray mData = new JSONArray();// JSON數據源
private View view_page_footer;// 底部視圖
private int num = 1;// 載入數據計數
private int count = 50;// 總數據
// private boolean flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.weixin);
lv = (ListView) findViewById(R.id.lv);
getJSONArray(mData);
mJson = new MyWeixinJSON(mData, this);
view_page_footer = LayoutInflater.from(this).inflate(
R.layout.view_page_footer, null);
lv.addFooterView(view_page_footer);// 添加底部視圖
TextView text_page = (TextView) view_page_footer.findViewById(R.id.text_page);
text_page.setOnClickListener(new View.OnClickListener() {
// 點擊按鈕 追加數據 並通知適配器
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv = (TextView) v;
tv.setText("正在載入中...");
getJSONArray(mData);
tv.setText("下一頁");
mJson.notifyDataSetChanged();
}
});
lv.setAdapter(mJson);// 綁定適配器
}
/** 數據源JSONArray */
private void getJSONArray(JSONArray jArray) {
try {
for (int i = 1; i <= 5; i++) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", "姓名" + num++);
jsonObject.put("time", "9月29日");
jsonObject.put("info", "我通過了你的好友驗證請求,現在我們可以開始對話啦");
jsonObject.put("img", R.drawable.special_spring_head2);
jArray.put(jsonObject);
if (num == count) {
lv.removeFooterView(view_page_footer);
Toast.makeText(this, "沒有更多數據了...", Toast.LENGTH_LONG)
.show();
}
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
其中,所添加的底部視圖,只有一個供點擊追加的按鈕:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/text_page"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="下一頁"
android:gravity="center"/>
</LinearLayout>
其中,所添加的底部視圖,只有一個供點擊追加的按鈕:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/text_page"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="下一頁"
android:gravity="center"/>
</LinearLayout>
效果圖
Ⅷ Android listview 的用法 越詳細越好。
Android listview與adapter用法
listview與adapter用法
一個ListView通常有兩個職責。
(1)將數據填充到布局。
(2)處理用戶的選擇點擊等操作。
第一點很好理解,ListView就是實現這個功能的。第二點也不難做到,在後面的學習中讀者會發現,這非常簡單。
一個ListView的創建需要3個元素。
(1)ListView中的每一列的View。
(2)填入View的數據或者圖片等。
(3)連接數據與ListView的適配器。
也就是說,要使用ListView,首先要了解什麼是適配器。適配器是一個連接數據和AdapterView(ListView就是一個典型的AdapterView,後面還會學習其他的)的橋梁,通過它能有效地實現數據與AdapterView的分離設置,使AdapterView與數據的綁定更加簡便,修改更加方便
Android中提供了很多的Adapter,表4-5列出了常用的幾個。
表4-5 常用適配器
Adapter
含義
ArrayAdapter<T>
用來綁定一個數組,支持泛型操作
SimpleAdapter
用來綁定在xml中定義的控制項對應的數據
SimpleCursorAdapter
用來綁定游標得到的數據
BaseAdapter
通用的基礎適配器
其實適配器還有很多,要注意的是,各種Adapter只不過是轉換的方式和能力不一樣而已。下面就通過使用不同的Adapter來為ListView綁定數據(SimpleCursorAdapter暫且不講,後面講SQLite時會介紹)。
4.12.1 ListView使用ArrayAdapter
用ArrayAdapter可以實現簡單的ListView的數據綁定。默認情況下,ArrayAdapter綁定每個對象的toString值到layout中預先定義的TextView控制項上。ArrayAdapter的使用非常簡單。
實例:
工程目錄:EX_04_12
在布局文件中加入一個ListView控制項。
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="
http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <!-- 添加一個ListView控制項 --> <ListView
android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</LinearLayout>
然後在Activity中初始化。
publicclass MyListView extends Activity {
privatestaticfinal String[] strs = new String[] {
"first", "second", "third", "fourth", "fifth"
};//定義一個String數組用來顯示ListView的內容private ListView lv;/** Called when the activity is first created. */
@Override
publicvoid onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView) findViewById(R.id.lv);//得到ListView對象的引用 /*為ListView設置Adapter來綁定數據*/
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, strs));
}
}
▲圖4-29 ListView使用ArrayAdapter運行效果
代碼非常的簡單,運行效果如圖4-29所示。
分析一下使用的步驟。
(1)定義一個數組來存放ListView中item的內容。
(2)通過實現ArrayAdapter的構造函數來創建一個ArrayAdapter的對象。
(3)通過ListView的setAdapter()方法綁定ArrayAdapter。
其中第二步有必要說一下的是,ArrayAdapter有多個構造函數,例子中實現的是最常用的一種。第一個參數為上下文,第二個參數為一個包含TextView,用來填充ListView的每一行的布局資源ID。第三個參數為ListView的內容。其中第二個參數可以自定義一個layout,但是這個layout必須要有TextView控制項。通常我們使用Android提供的資源,除了例子中所用的,常用的還有如下幾種,可實現帶RadioButton和CheckBox的ListView。
(1)通過指定android.R.layout.simple_list_item_checked這個資源,實現帶選擇框的ListView。需要用setChoiceMode()方法設定選擇為多選還是單選,否則將不能實現選擇效果,運行效果如圖4-30所示。
實現代碼如下:
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, strs));
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
(2)通過指定android.R.layout.simple_list_item_multiple_choice這個資源實現帶CheckBox的ListView。同樣的,需要用setChoiceMode()方法來設置單選或者多選,運行效果如圖4-31所示。
實現代碼如下:
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, strs));
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
(3)通過指定android.R.layout.simple_list_item_single_choice這個資源實現帶RadioButton的ListView。這里要注意的是,這里並不是指定了單選。是多選還是單選要通過setChoiceMode()方法來指定,運行效果如圖4-32所示。
實現代碼如下:
lv.setAdapter(newArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,strs));
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
在前面講到過,ListView的職責除了填充數據外,還要處理用戶的操作。通過如下的代碼就可以為ListView綁定一個點擊監聽器,點擊後在標題欄顯示點擊的行數。
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
//點擊後在標題上顯示點擊了第幾行 setTitle("你點擊了第"+arg2+"行");
}
});
4.12.2 ListView使用SimpleAdapter
很多時候需要在列表中展示一些除了文字以外的東西,比如圖片等。這時候可以使用SimpleAdapter。SimpleAdapter的使用也非常簡單,同時它的功能也非常強大。可以通過它自定義ListView中的item的內容,比如圖片、多選框等。看一個例子,實現一個每一行都有一個ImageView和TextView的ListView。先看一下運行效果,如圖4-34所示。
▲圖4-34 帶圖標的ListView
首先在布局文件中增加一個ListView控制項。
還需要定義一個ListView中每一行的布局,用RelativeLayout來實現一個帶兩行字和一個圖片的布局。
item.xml:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ImageViewandroid:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/ItemImage"/>
<TextViewandroid:id="@+id/ItemTitle" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textSize="20sp"/>
<TextViewandroid:id="@+id/ItemText" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_below="@+id/ItemTitle"/> </RelativeLayout>
配置完畢,就可以在Java代碼中為ListView綁定數據。
publicclass MyListViewSimple extends Activity {
private ListView lv;
/** Called when the activity is first created. */ @Override
publicvoid onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView) findViewById(R.id.lv);/*定義一個動態數組*/
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();/*在數組中存放數據*/
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.icon);//加入圖片 map.put("ItemTitle", "第"+i+"行");
map.put("ItemText", "這是第"+i+"行");
listItem.add(map);
}
SimpleAdapter mSimpleAdapter = new SimpleAdapter(this,listItem,//需要綁定的數據
R.layout.item,//每一行的布局//動態數組中的數據源的鍵對應到定義布局的View中new String[] {"ItemImage"
,"ItemTitle", "ItemText"},
newint[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}
);
lv.setAdapter(mSimpleAdapter);//為ListView綁定適配器 lv.setOnItemClickListener(new
OnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
setTitle("你點擊了第"+arg2+"行");//設置標題欄顯示點擊的行
}
});
}
}
使用simpleAdapter的數據一般都是用HashMap構成的列表,列表的每一節對應ListView的每一行。通過SimpleAdapter的構造函數,將HashMap的每個鍵的數據映射到布局文件中對應控制項上。這個布局文件一般根據自己的需要來自己定義。梳理一下使用SimpleAdapter的步驟。
(1)根據需要定義ListView每行所實現的布局。
(2)定義一個HashMap構成的列表,將數據以鍵值對的方式存放在裡面。
(3)構造SimpleAdapter對象。
(4)將LsitView綁定到SimpleAdapter上。
4.12.3 ListView使用BaseAdapter與ListView的優化
在ListView的使用中,有時候還需要在裡面加入按鈕等控制項,實現單獨的操作。也就是說,這個ListView不再只是展示數據,也不僅僅是這一行要來處理用戶的操作,而是裡面的控制項要獲得用戶的焦點。讀者可以試試用SimpleAdapter添加一個按鈕到ListView的條目中,會發現可以添加,但是卻無法獲得焦點,點擊操作被ListView的Item所覆蓋。這時候最方便的方法就是使用靈活的適配器BaseAdapter了。
使用simpleAdapter的數據一般都是用HashMap構成的列表,列表的每一節對應ListView的每一行。通過SimpleAdapter的構造函數,將HashMap的每個鍵的數據映射到布局文件中對應控制項上。這個布局文件一般根據自己的需要來自己定義。梳理一下使用SimpleAdapter的步驟。
(1)根據需要定義ListView每行所實現的布局。
(2)定義一個HashMap構成的列表,將數據以鍵值對的方式存放在裡面。
(3)構造SimpleAdapter對象。
(4)將LsitView綁定到SimpleAdapter上。
4.12.3 ListView使用BaseAdapter與ListView的優化
在ListView的使用中,有時候還需要在裡面加入按鈕等控制項,實現單獨的操作。也就是說,這個ListView不再只是展示數據,也不僅僅是這一行要來處理用戶的操作,而是裡面的控制項要獲得用戶的焦點。讀者可以試試用SimpleAdapter添加一個按鈕到ListView的條目中,會發現可以添加,但是卻無法獲得焦點,點擊操作被ListView的Item所覆蓋。這時候最方便的方法就是使用靈活的適配器BaseAdapter了。
【內容較多,可以自己去看】
[轉自:http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html]
Ⅸ 「Unable to access Android SDK add-on list」是
意思是:無法訪問Android插件列表。
Ⅹ 在android中 List 和ArrayList的區別,越詳細越好
List是一個介面,而ArrayList是List的一個實現類,對於android和J2SE來講,兩者之間的區別不大。