最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程開發(fā)之Spinner組件用法

 更新時間:2015年12月23日 09:26:43   作者:java2009cgh  
這篇文章主要介紹了Android編程開發(fā)之Spinner組件用法,結合實例形式分析介紹了Android中Spinner組件的功能、定義及具體使用技巧,需要的朋友可以參考下

本文實例講述了Android編程開發(fā)之Spinner組件用法。分享給大家供大家參考,具體如下:

Spinner組件組要用顯示一個下拉列表,在使用中需要用到適配器Adapter,下面是一個該組件的使用示例

首先是布局文件main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" android:layout_width="fill_parent" 
 android:layout_height="fill_parent"> 
 <Spinner android:id="@+id/spinner1" android:layout_width="fill_parent" 
  android:layout_height="wrap_content" /> 
 <Spinner android:id="@+id/spinner2" android:layout_width="fill_parent" 
  android:layout_height="wrap_content" android:layout_marginTop="20dp"/>
</LinearLayout> 

由于用到simpAdapter所以要寫子項Item的布局如下 item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="horizontal" android:layout_width="fill_parent" 
 android:layout_height="wrap_content"> 
 <ImageView android:id="@+id/ivLogo" android:layout_width="60dp" 
  android:layout_height="60dp" android:src="@drawable/icon" 
  android:paddingLeft="10dp" /> 
 <TextView android:id="@+id/tvApplicationName" android:textColor="#000" 
  android:layout_width="wrap_content" android:layout_height="fill_parent" 
  android:textSize="16dp" android:gravity="center_vertical" 
  android:paddingLeft="10dp" /> 
</LinearLayout> 

下面是代碼:

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.SimpleAdapter; 
import android.widget.Spinner; 
import android.widget.AdapterView.OnItemSelectedListener; 
public class Main extends Activity 
{ 
 @Override 
 public void onCreate(Bundle savedInstanceState) 
 { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.main); 
  //獲取對象 
  Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); 
  String[] applicationNames = new String[] 
  { "多功能日歷", "eoeMarket客戶端", "耐玩的重力消磚塊", "白社會", "程序終結者" }; 
  ArrayAdapter<String> aaAdapter = new ArrayAdapter<String>(this, 
    android.R.layout.simple_spinner_item, applicationNames); 
  // 將如下代碼可以使列表項帶RadioButton組件 
  // aaAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
  spinner1.setAdapter(aaAdapter); 
  Spinner spinner2 = (Spinner) findViewById(R.id.spinner2); 
  final List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(); 
  Map<String, Object> item1 = new HashMap<String, Object>(); 
  item1.put("ivLogo", R.drawable.calendar); 
  item1.put("tvApplicationName", "多功能日歷"); 
  Map<String, Object> item2 = new HashMap<String, Object>(); 
  item2.put("ivLogo", R.drawable.eoemarket); 
  item2.put("tvApplicationName", "eoeMarket客戶端"); 
  items.add(item1); 
  items.add(item2); 
  SimpleAdapter simpleAdapter = new SimpleAdapter(this, items, 
    R.layout.item, new String[] 
    { "ivLogo", "tvApplicationName" }, new int[] 
    { R.id.ivLogo, R.id.tvApplicationName }); 
  spinner2.setAdapter(simpleAdapter); 
  //為Spinner2加上監(jiān)聽事件 
  spinner2.setOnItemSelectedListener(new OnItemSelectedListener() 
  { 
   @Override 
   public void onItemSelected(AdapterView<?> parent, View view, 
     int position, long id) 
   { 
     new AlertDialog.Builder(view.getContext()).setTitle( 
       items.get(position).get("tvApplicationName") 
         .toString()).setIcon( 
       Integer.parseInt(items.get(position).get("ivLogo")
         .toString())).show(); 
   } 
   @Override 
   public void onNothingSelected(AdapterView<?> parent) 
   {
   } 
  }); 
 } 
}

希望本文所述對大家Android程序設計有所幫助。

相關文章

  • 用Android實現京東秒殺功能詳解

    用Android實現京東秒殺功能詳解

    大家好,本篇文章主要講的是用Android實現京東秒殺功能詳解,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01
  • Flutter 中的PageStorage小部件使用及最佳實踐

    Flutter 中的PageStorage小部件使用及最佳實踐

    在Flutter中,PageStorage小部件提供了一種方法來保存和恢復頁面間的信息,這對于具有多個頁面且需要在這些頁面之間共享狀態(tài)的應用程序非常有用,本文將詳細介紹PageStorage的用途、如何使用它以及一些最佳實踐,感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • Android使用viewpager實現自動無限輪播圖

    Android使用viewpager實現自動無限輪播圖

    這篇文章主要介紹了Android使用viewpager實現自動無限輪播圖效果,實現方法大概有兩種,一種是viewpager+作為游標的點 。另外一種是重寫viewpager,具體實現過程大家參考下本文
    2018-06-06
  • ViewPager實現輪播圖引導頁

    ViewPager實現輪播圖引導頁

    這篇文章主要為大家詳細介紹了ViewPager實現輪播圖引導頁,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Android之日期時間選擇控件DatePicker和TimePicker實例

    Android之日期時間選擇控件DatePicker和TimePicker實例

    本篇文章主要介紹了Android之日期時間選擇控件DatePicker和TimePicker實例,具有一定的參考價值,有興趣的可以了解一下
    2017-05-05
  • Android使用硬件加速的方式

    Android使用硬件加速的方式

    硬件加速是指利用設備的硬件資源來加速圖形渲染和圖像處理等操作,以提高應用程序的性能和用戶體驗,Android使用硬件加速的目的是為了提高圖形渲染的性能和效果,本文給大家詳細介紹了Android如何使用硬件加速,需要的朋友可以參考下
    2023-10-10
  • 詳解 android 光線傳感器 light sensor的使用

    詳解 android 光線傳感器 light sensor的使用

    這篇文章主要介紹了詳解 android 光線傳感器 light sensor的使用的相關資料,需要的朋友可以參考下
    2017-06-06
  • Flutter 開發(fā)一個登錄頁面

    Flutter 開發(fā)一個登錄頁面

    登錄頁面在 App 開發(fā)中非常常見,本篇借登錄頁面的開發(fā)介紹了文本框 TextField組件的使用,同時使用文本框的裝飾屬性實現了個性化文本框設置。
    2021-06-06
  • Android中通過訪問本地相冊或者相機設置用戶頭像實例

    Android中通過訪問本地相冊或者相機設置用戶頭像實例

    本篇文章主要介紹了Android中通過訪問本地相冊或者相機設置用戶頭像,具有一定的參考價值,有興趣的可以了解一下。
    2017-01-01
  • Android開發(fā)中Intent.Action各種常見的作用匯總

    Android開發(fā)中Intent.Action各種常見的作用匯總

    今天小編就為大家分享一篇關于Android開發(fā)中Intent.Action各種常見的作用匯總,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12

最新評論

德格县| 抚松县| 镇康县| 苏尼特右旗| 名山县| 民勤县| 大埔区| 五峰| 乌拉特前旗| 安塞县| 北碚区| 新丰县| 界首市| 武川县| 延川县| 泌阳县| 盘锦市| 勐海县| 田阳县| 芜湖市| 桃园市| 江安县| 宜春市| 三都| 来宾市| 宣化县| 息烽县| 昌图县| 巴青县| 图们市| 甘肃省| 文成县| 沙坪坝区| 鸡东县| 康定县| 鸡西市| 炎陵县| 新闻| 郴州市| 旬阳县| 安泽县|