高階控制項Spinner

2021-07-23 04:25:14 字數 2838 閱讀 6408

spinner

>概念;下拉列表控制項 預設顯示當前選擇的項(第一次展示集合中第一條資料)

>屬性:

android:entries="@array/books"  展示資料  (note:提前知道資料是什麼 )

android:spinnermode="dropdown" spinner 樣式

dropdown:下拉列表 設定popupbackground 每一項的背景顏色

dialog:彈出框 設定prompt 標題 呼叫的是values/string.xml/string

>監聽:setonitemselectedlistener

2,什麼是adapter?

>介面卡  將資料轉換成控制項識別的形式

>子類:baseadapter   arrayadapter     ******adapter

3,arrayadapter的使用?

>一般用於只有string型別資料  展示到textview上

>如果三個引數的arrayadapter   item布局的根節點 必須是textview

如果跟節點不是textview 三個引數的會報錯      使用四個引數的arrayadapter

4,******adapter的使用:

>處理複雜的資料   (帶有和文字)

context context:   上下文

list<? extends map> data:  資料來源

int resource:  布局

string from:  資料來源中帶key的陣列

int to     :  布局資源中id的陣列

note:from裡的key和to裡的控制項id  是對應關係

5,autocompletetextview

>自動索引的edittext(文字輸入框)

> 預設輸入倆個字元  才開始索引

android:completionthreshold="1" 輸入幾個字元開始索引

6,addtextchangedlistener()的用法?

>

//文字發生變化的監聽   可以對edittext操作 

autoview.addtextchangedlistener(new textwatcher()

/*** 改變文字之前呼叫

* charsequence s:變化之前的文字

* int start:變化之前的文字下標

* int count:相比較文字的變化   新增不變的0   刪除是改變:刪除幾個展示結果

* int after:相比較文字的變化     如果新增是有值    如果刪除不變   0

*/@override

public void beforetextchanged(charsequence s, int start, int count,

int after)

/*** 改變文字之後呼叫

* editable s:改變之後的文字

*/@override

public void aftertextchanged(editable s)

});/**

* 08-25 15:23:44.334: e/aaa(12812): ==beforetextchanged==s:=start:0=count:0=after:1

08-25 15:23:44.334: e/aaa(12812): ==ontextchanged==s:g=start:0=before:0=count:1

08-25 15:23:44.334: e/aaa(12812): ==aftertextchanged==s:g

08-25 15:23:45.904: e/aaa(12812): ==beforetextchanged==s:g=start:1=count:0=after:1

08-25 15:23:45.904: e/aaa(12812): ==ontextchanged==s:gh=start:1=before:0=count:1

08-25 15:23:45.904: e/aaa(12812): ==aftertextchanged==s:gh

08-25 15:23:47.824: e/aaa(12812): ==beforetextchanged==s:gh=start:2=count:0=after:1

08-25 15:23:47.824: e/aaa(12812): ==ontextchanged==s:ghj=start:2=before:0=count:1

08-25 15:23:47.824: e/aaa(12812): ==aftertextchanged==s:ghj

08-25 15:23:49.164: e/aaa(12812): ==beforetextchanged==s:ghj=start:2=count:1=after:0

08-25 15:23:49.164: e/aaa(12812): ==ontextchanged==s:gh=start:2=before:1=count:0

08-25 15:23:49.164: e/aaa(12812): ==aftertextchanged==s:gh

08-25 15:23:49.694: e/aaa(12812): ==beforetextchanged==s:gh=start:1=count:1=after:0

08-25 15:23:49.694: e/aaa(12812): ==ontextchanged==s:g=start:1=before:1=count:0

08-25 15:23:49.694: e/aaa(12812): ==aftertextchanged==s:g

Spinner控制項 下拉列表

簡單的spinner舉例,一言不合上 第2步載入介面卡和第3步設定下拉樣式都是採用android自帶的樣式哦 自定義spinner控制項 1.設定資料來源 getdata 2.配置介面卡 adapter 2 new adapter spinneractivity.this,lists 2,r.lay...

安卓學習 spinner控制項

安卓提供了一種下拉列表式的控制項 spinner,實現這個控制項主要就是配置arrayadapter這個介面卡,下面就記錄配置該介面卡的兩種方法。一.通過createfromresource方法建立乙個arrayadapter物件 1.首先在布局檔案中定義乙個spinner控制項 2.建立乙個arr...

控制項Spinner的基本使用

spinner控制項是下拉顯示控制項,基本使用很容易掌握 1.在xml中插入spinner控制項的布局myspin 2.在xml中設定spinner的選定顯示文字的格式 3.在 中呼叫,並設定spinner的值 設定陣列取值範圍 private static final string an int ...