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

Android ListView中動態(tài)添加RaidoButton的實例詳解

 更新時間:2017年08月16日 11:37:27   投稿:lqh  
這篇文章主要介紹了Android ListView中動態(tài)添加RaidoButton的實例詳解的相關資料,需要的朋友可以參考下

Android ListView中動態(tài)添加RaidoButton的實例詳解

這里講解的內(nèi)容是:從數(shù)據(jù)庫中取得數(shù)據(jù),將這些數(shù)據(jù)的value值賦值給Radiobutton的text屬性,將這些數(shù)據(jù)的key值賦值給radiobutton的key值。同時實現(xiàn)點擊一整行,更換radiobutton選擇。

XML代碼:主要是添加一個ListView控件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" > 
 
   <ListView android:id="@+id/ListView01"   
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"/>  
 
</RelativeLayout> 

下面是后臺代碼

說明:這里沒有將需要引入的包貼出來,只是列舉了其中重要的部分。

public class TestActivity extends Activity { 
   
   //初始化字符數(shù)組:arrayValue用于存放數(shù)據(jù)庫中取得的key值,arrayText用于存放數(shù)據(jù)庫中取得的Value值 
   String[] arrayValue; 
   String[] arrayText; 
    
  @Override 
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_test_item);     
     
    //保證線程安全,防止多線程同時運行 
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 
    .detectDiskReads() 
    .detectDiskWrites() 
    .detectAll()   
    .build()); 
     
    //初始化DBHelper 
     final DBHelper dbHelper = new DBHelper(this); 
     //查詢業(yè)務類型語句 
     String sql = "select * from t_Test";   
     final Cursor cur = dbHelper.select(sql); 
      
    // 防止數(shù)據(jù)庫中無數(shù)據(jù)出錯 
    if (cur != null && cur.getCount() > 0) { 
      arrayText = new String[cur.getCount()]; 
      arrayValue = new String[cur.getCount()]; 
      // 移動到第一條記錄 
      cur.moveToFirst(); 
      int i = 0; 
      int index = 0; 
      // 遍歷Cursor,把數(shù)據(jù)添加到數(shù)組中 
      while (!cur.isAfterLast()) { 
        index = cur.getColumnIndex("要查找的列名"); 
        arrayText[i] = cur.getString(index); 
        index = cur.getColumnIndex("id"); 
        arrayValue[i] = cur.getString(index); 
        i++; 
        cur.moveToNext(); // 移動到下一條記錄 
      } 
    } 
       
      String[] contentString = arrayText; 
      //創(chuàng)建listview適配器,存放取得的radiobutton 
      ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>( this,  
          android.R.layout.simple_list_item_single_choice,  
          contentString);  
      ListView mylist = (ListView)findViewById(R.id.ListView01);  
      mylist.setAdapter(arrayAdapter);     
       
      //radiobutton監(jiān)聽事件 
      mylist.setOnItemClickListener(new OnItemClickListener() { 
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
            long arg3) {           
          //將選擇的radiobutton的Value值傳入到實體類ApplicationData中 
          appData.BusinessID =arrayValue[arg2]; 
           
        } 
      });  
      //設置選擇模式:單選模式 
      mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);  
  
  } 
 
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_business_item, menu); 
    return true; 
  }   
} 

以上就是Android ListView中動態(tài)添加RaidoButton的實例,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • Android數(shù)據(jù)加密之Aes加密

    Android數(shù)據(jù)加密之Aes加密

    這篇文章主要為大家詳細介紹了Android數(shù)據(jù)加密之Aes加密,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android Studio 3.x安裝指南教程

    Android Studio 3.x安裝指南教程

    這篇文章主要為大家詳細介紹了Android Studio 3.x安裝指南教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Android實現(xiàn)關機與重啟的幾種方式(推薦)

    Android實現(xiàn)關機與重啟的幾種方式(推薦)

    這篇文章主要介紹了Android實現(xiàn)關機與重啟的幾種方式(推薦)的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • Android實現(xiàn)登錄注冊頁面(下)

    Android實現(xiàn)登錄注冊頁面(下)

    這篇文章主要介紹了Android實現(xiàn)登錄注冊頁面的第二篇,實現(xiàn)驗證登錄和記住密碼功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android 用HttpURLConnection訪問網(wǎng)絡的方法

    Android 用HttpURLConnection訪問網(wǎng)絡的方法

    下面小編就為大家分享一篇Android 用HttpURLConnection訪問網(wǎng)絡的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android常見XML轉義字符(總結)

    Android常見XML轉義字符(總結)

    下面小編就為大家?guī)硪黄狝ndroid常見XML轉義字符(總結)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android編寫簡單的聊天室應用

    Android編寫簡單的聊天室應用

    這篇文章主要為大家詳細介紹了Android實現(xiàn)簡單聊天室的相關資料,具有發(fā)送表情,更改頭像等功能
    2016-06-06
  • 簡單介紹Android開發(fā)中的Activity控件的基本概念

    簡單介紹Android開發(fā)中的Activity控件的基本概念

    這篇文章主要介紹了Android開發(fā)中的Activity控件的基本概念,Activity控件的使用是安卓開發(fā)的基礎之一,需要的朋友可以參考下
    2015-12-12
  • Android使用網(wǎng)絡獲取定位的方法

    Android使用網(wǎng)絡獲取定位的方法

    這篇文章主要為大家詳細介紹了Android使用網(wǎng)絡獲取定位的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Android開發(fā)中滑動分頁功能實例詳解

    Android開發(fā)中滑動分頁功能實例詳解

    這篇文章主要介紹了Android開發(fā)中滑動分頁功能,結合實例形式詳細分析了Android滑動分頁功能的具體步驟與相關實現(xiàn)技巧,代碼中備有詳盡的注釋便于理解,需要的朋友可以參考下
    2017-10-10

最新評論