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

Android Studio綁定下拉框數(shù)據(jù)詳解

 更新時(shí)間:2017年10月13日 09:25:18   作者:龍魂學(xué)者  
這篇文章主要為大家詳細(xì)介紹了Android Studio綁定下拉框數(shù)據(jù),Android Studio綁定網(wǎng)絡(luò)JSON數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

效果顯示:

這里寫圖片描述
這里寫圖片描述

1、頁面xml代碼(項(xiàng)目的代碼,直接復(fù)制會(huì)有錯(cuò),自己修改一下就好)

<TextView
 android:id="@+id/consultation_tv_section"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_above="@+id/consultation_et_doctor"
 android:layout_alignLeft="@+id/consultation_tv_phone"
 android:layout_alignStart="@+id/consultation_tv_phone"
 android:layout_marginBottom="8dp"
 android:text="掛號科室:"
 android:textColor="@color/black"
 android:textSize="18sp"
 android:textStyle="bold" />

<Spinner
 android:id="@+id/consultation_et_section"
 android:layout_width="260dp"
 android:layout_height="40dp"
 android:layout_alignLeft="@+id/consultation_et_phone"
 android:layout_alignStart="@+id/consultation_et_phone"
 android:layout_below="@+id/consultation_et_phone"
 android:layout_marginTop="22dp"
 android:background="@drawable/input_bg"
 android:ems="10"
 android:inputType="textPersonName"
 android:paddingLeft="15dp"
 android:paddingRight="15dp"
 android:spinnerMode="dialog" />

2、java創(chuàng)建自定義參數(shù)

Spinner consultation_et_section;//掛號科室:

3、獲取選擇控件(Spinner)

consultation_et_section = (Spinner) findViewById(R.id.consultation_et_section);

4、獲取JSON數(shù)據(jù)和綁定數(shù)據(jù),可以參考前一篇文章

(1)、創(chuàng)建自定義參數(shù)

List<String> listMemDoctorData = null;

(2)、獲取數(shù)據(jù)和綁定數(shù)據(jù)

/**
 * 獲取JSON醫(yī)生信息數(shù)據(jù)
 */
public void findDoctorData(int sectionId){
 AsyncHttpClient client = new AsyncHttpClient();
 client.get(AbAppConfig.DATA_URL + "appGVConsultation/findDoctorData?sectionId="+sectionId, null, new AsyncHttpResponseHandler() {
  @Override
  public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
   try {
    JSONObject object = new JSONObject(new String(responseBody));//獲取json數(shù)據(jù)
    JSONArray jsonArray = object.getJSONArray("obj");//獲取數(shù)據(jù)集名稱為obj的數(shù)據(jù)
    Log.d("jsonArray數(shù)據(jù)輸出:", String.valueOf(jsonArray));
    listMemDoctor = new ArrayList<>();
    for (int i = 0; i < jsonArray.length();i++) {
     MemDoctor doctor = MemDoctor.doctorData(jsonArray.getJSONObject(i));//把數(shù)據(jù)存在novels集合中
     if (doctor != null){
      listMemDoctor.add(doctor);
     }
    }

    if (jsonArray.length() > 0){
     listMemDoctorData = new ArrayList<>();
     doctor_id = listMemDoctor.get(0).id;//獲取第一個(gè)醫(yī)生的ID
     for (int i = 0; i < listMemDoctor.size(); i++){
      MemDoctor section = listMemDoctor.get(i);
      listMemDoctorData.add(section.doctorName);
     }

     //建立 Adapter并且綁定數(shù)據(jù)源
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(GV_Consultation.this, android.R.layout.simple_spinner_item, listMemDoctorData);
     //設(shè)置樣式
     arrayAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
     //綁定 Adapter到控件
     consultation_et_doctor.setAdapter(arrayAdapter);
    }else {
     consultation_et_doctor.setAdapter(null);
     doctor_id = 0;
     Toast.makeText(GV_Consultation.this, "該科室沒有醫(yī)生信息數(shù)據(jù)", Toast.LENGTH_SHORT).show();
    }

   } catch (JSONException e) {
    Toast.makeText(GV_Consultation.this, "數(shù)據(jù)請求失敗,請稍后重試", Toast.LENGTH_SHORT).show();
   }
  }

  @Override
  public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
   //請求失敗的回調(diào)處理
   Toast.makeText(GV_Consultation.this, "請鏈接網(wǎng)絡(luò),稍后重試", Toast.LENGTH_SHORT).show();
  }
 });
}


5、創(chuàng)建點(diǎn)擊事件

//醫(yī)生選擇點(diǎn)擊事件
consultation_et_doctor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
 @Override
 public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
 doctor_id = listMemDoctor.get((int) id).id;//獲取選擇醫(yī)生的ID
 }
 @Override
 public void onNothingSelected(AdapterView<?> parent) {
 }
});

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android獲取assets文件夾中的數(shù)據(jù)并寫入SD卡示例

    Android獲取assets文件夾中的數(shù)據(jù)并寫入SD卡示例

    這篇文章主要介紹了Android獲取assets文件夾中的數(shù)據(jù)并寫入SD卡示例,對初學(xué)Android開發(fā)的朋友來說是一個(gè)很實(shí)用的功能,需要的朋友可以參考下
    2014-07-07
  • Android封裝Banner控件方法介紹

    Android封裝Banner控件方法介紹

    android-banner實(shí)現(xiàn)了一般banner循環(huán)輪播的效果,一頁只顯示一張圖片,也可以一頁顯示一張圖和相鄰兩個(gè)圖片的一部分,此項(xiàng)目僅僅是banner展示圖片,沒有多余的諸如指示器、頁面切換動(dòng)畫等效果代碼,詳見效果圖和案例代碼
    2023-03-03
  • Android 加載大圖及多圖避免程序出現(xiàn)OOM(OutOfMemory)異常

    Android 加載大圖及多圖避免程序出現(xiàn)OOM(OutOfMemory)異常

    這篇文章主要介紹了Android 加載大圖及多圖避免程序出現(xiàn)OOM(OutOfMemory)異常的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android開發(fā)服務(wù)Service全面講解

    Android開發(fā)服務(wù)Service全面講解

    Android的服務(wù)是開發(fā)Android應(yīng)用程序的重要組成部分。不同于活動(dòng)Activity,服務(wù)是在后臺(tái)運(yùn)行,服務(wù)沒有接口,生命周期也與活動(dòng)Activity非常不同。通過使用服務(wù)我們可以實(shí)現(xiàn)一些后臺(tái)操作,比如想從遠(yuǎn)程服務(wù)器加載一個(gè)網(wǎng)頁等,下面來看看詳細(xì)內(nèi)容,需要的朋友可以參考下
    2023-02-02
  • Android動(dòng)態(tài)顯示當(dāng)前年月日時(shí)分秒系統(tǒng)時(shí)間(示例代碼)

    Android動(dòng)態(tài)顯示當(dāng)前年月日時(shí)分秒系統(tǒng)時(shí)間(示例代碼)

    這篇文章主要介紹了Android動(dòng)態(tài)顯示當(dāng)前年月日時(shí)分秒系統(tǒng)時(shí)間的示例代碼,需要的朋友可以參考下
    2017-05-05
  • 以一個(gè)著色游戲展開講解Android中區(qū)域圖像填色的方法

    以一個(gè)著色游戲展開講解Android中區(qū)域圖像填色的方法

    這篇文章主要介紹了Android中實(shí)現(xiàn)區(qū)域圖像顏色填充的方法,文中以一個(gè)著色游戲?yàn)槔v解了邊界的填充等各種填色操作,需要的朋友可以參考下
    2016-02-02
  • Android性能優(yōu)化之圖片大小,尺寸壓縮綜合解決方案

    Android性能優(yōu)化之圖片大小,尺寸壓縮綜合解決方案

    隨著Android手機(jī)的越來越先進(jìn),給我們開發(fā)者而言傳遞的圖片也是越來越大,這個(gè)時(shí)候我們可以對一些沒有必要原圖展示的圖片進(jìn)行壓縮,這篇文章主要給大家介紹了關(guān)于Android性能優(yōu)化之圖片大小,尺寸壓縮的綜合解決方案,需要的朋友可以參考下
    2022-04-04
  • Android中ExpandableListView使用示例詳解

    Android中ExpandableListView使用示例詳解

    這篇文章主要為大家詳細(xì)介紹了Android中ExpandableListView使用示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android中WebView常見問題及解決方案匯總

    Android中WebView常見問題及解決方案匯總

    本篇文章主要介紹了Android中WebView常見問題及解決方案匯總,把WebView遇到的問題詳細(xì)的羅列下來,有需要的朋友可以了解一下。
    2016-11-11
  • Android開發(fā)X Y軸Board的繪制教程示例

    Android開發(fā)X Y軸Board的繪制教程示例

    這篇文章主要為大家介紹了Android開發(fā)X Y軸Board的繪制教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12

最新評論