欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

學(xué)習(xí)Android自定義Spinner適配器

 更新時(shí)間:2016年05月13日 08:51:51   作者:不正經(jīng)的小二哥  
這篇文章主要為大家詳細(xì)介紹了學(xué)習(xí)Android自定義Spinner適配器的相關(guān)資料,感興趣的小伙伴們可以參考一下

本文為大家分享Android自定義Spinner適配器的相關(guān)知識(shí)點(diǎn),供大家參考,具體內(nèi)容如下

一、大致效果

二.關(guān)鍵代碼

在注釋中講重點(diǎn)吧。
(1)Spinner的布局: car_brand_spinner.xml
即為彈出來(lái)的下拉列表的布局啦,后面的那個(gè)布局就不拿出來(lái)丟人現(xiàn)眼了,反正知道有一個(gè)Spinner的id為carBrandSpinner就可以了。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:orientation="horizontal">

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp">

    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="New Text"
      android:id="@+id/car_brand_name"
      android:layout_gravity="left"
      android:layout_alignParentLeft="true"
      android:layout_marginTop="5dp"
      android:layout_marginBottom="5dp" />

    <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/car_brand_flag"
      android:layout_gravity="right"
      android:layout_alignParentRight="true" />
  </RelativeLayout>
</LinearLayout>

(2)適配器

ArrayAdapter carBrandAdapter=new ArrayAdapter<String>
(
  AddCarActivity.this,
  android.R.layout.simple_spinner_dropdown_item,
  carBrandNameList//是String[],就是所有要顯示的brandName
){
  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
  convertView = View.inflate(AddCarActivity.this,R.layout.car_brand_spinner,null);//獲得Spinner布局View
  if(convertView!=null)
  {
    TextView carBrandNameView = (TextView)convertView.findViewById(R.id.car_brand_name);
    ImageView carBrandFlagView = (ImageView)convertView.findViewById(R.id.car_brand_flag);
    try
    {
      JSONObject json = new JSONObject(carBrandList.get(position).get("carBrand").toString());
      carBrandNameView.setText(json.getString("carBrandName"));//設(shè)置數(shù)據(jù),我這里的數(shù)據(jù)是從服務(wù)器讀出來(lái)的,所以前面有一個(gè)轉(zhuǎn)化取值的過(guò)程
      }catch (Exception e){}
      Bitmap bitmap =Common.String2Bitmap(carBrandList.get(position).get("carBrandFlagContent").toString());//這里也一樣,圖片數(shù)據(jù)來(lái)自于服務(wù)器,同時(shí)有一個(gè)將數(shù)據(jù)從String轉(zhuǎn)Bitmap的過(guò)程
      if(bitmap!=null)
      carBrandFlagView.setImageBitmap(bitmap);//顯示圖片
      }
      return convertView;
      }
};
//給Spinner set適配器
Spinner carBrandSpinner=(Spinner)findViewById(R.id.carBrandSpinner);
carBrandSpinner.setAdapter(carBrandAdapter);
carBrandSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
   @Override//重寫(xiě)Item被選擇的事件
   public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {}
   @Override
   public void onNothingSelected(AdapterView<?> parent) {}
});

到此結(jié)束!

以上就是關(guān)于Android Spinner適配器的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • Android實(shí)現(xiàn)截屏并保存操作功能

    Android實(shí)現(xiàn)截屏并保存操作功能

    這篇文章主要介紹了Android實(shí)現(xiàn)截屏操作功能,即Android中截取當(dāng)前屏幕的功能,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android編程開(kāi)發(fā)之ScrollView嵌套GridView的方法

    Android編程開(kāi)發(fā)之ScrollView嵌套GridView的方法

    這篇文章主要介紹了Android編程開(kāi)發(fā)之ScrollView嵌套GridView的方法,結(jié)合實(shí)例分析了ScrollView嵌套GridView的相關(guān)注意事項(xiàng)與處理技巧,需要的朋友可以參考下
    2015-12-12
  • Android 實(shí)現(xiàn)IOS選擇拍照相冊(cè)底部彈出的實(shí)例

    Android 實(shí)現(xiàn)IOS選擇拍照相冊(cè)底部彈出的實(shí)例

    這篇文章主要介紹了Android 實(shí)現(xiàn)IOS選擇拍照相冊(cè)底部彈出的實(shí)例的相關(guān)資料,這里提供了實(shí)現(xiàn)效果圖及實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2017-07-07
  • OkHttp3中默認(rèn)不保持Cookie的解決方法

    OkHttp3中默認(rèn)不保持Cookie的解決方法

    這篇文章主要給大家介紹了關(guān)于OkHttp3中默認(rèn)不保持Cookie的解決方法,文中先對(duì)OKhttp3中的cookies進(jìn)行了簡(jiǎn)單的介紹,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • Android sqlite cursor的遍歷實(shí)例詳解

    Android sqlite cursor的遍歷實(shí)例詳解

    在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于Android sqlite cursor的遍歷的相關(guān)實(shí)例及知識(shí)點(diǎn),需要的朋友們可以學(xué)習(xí)下。
    2021-06-06
  • Android使用EditText小技巧匯總

    Android使用EditText小技巧匯總

    這篇文章主要介紹了Android使用EditText的小技巧匯總,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-05-05
  • Android中Volley框架進(jìn)行請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)的使用

    Android中Volley框架進(jìn)行請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)的使用

    這篇文章主要介紹了Android中Volley框架進(jìn)行請(qǐng)求網(wǎng)絡(luò)數(shù)據(jù)的使用,本文給大家介紹的非常詳細(xì)具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-10-10
  • Android Studio升級(jí)到3.0后遇到的坑

    Android Studio升級(jí)到3.0后遇到的坑

    自從谷歌發(fā)布Android Studio 3.0版本后,一直心向往之,終于抽時(shí)間做了下升級(jí)處理,現(xiàn)在把升級(jí)過(guò)程中遇到的一些問(wèn)題以及解決方案分享給大家,希望對(duì)大家能給有事幫助
    2017-11-11
  • Android小程序?qū)崿F(xiàn)簡(jiǎn)易QQ界面

    Android小程序?qū)崿F(xiàn)簡(jiǎn)易QQ界面

    這篇文章主要為大家詳細(xì)介紹了Android小程序?qū)崿F(xiàn)簡(jiǎn)易QQ界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • 總是聽(tīng)到有人說(shuō)AndroidX,到底什么是AndroidX

    總是聽(tīng)到有人說(shuō)AndroidX,到底什么是AndroidX

    這篇文章主要介紹了總是聽(tīng)到有人說(shuō)AndroidX,到底什么是AndroidX,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05

最新評(píng)論