久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Android ExpandableListview 如何用循環(huán)把 組和子元素展示出來

瀏覽:188日期:2024-08-30 18:33:43

問題描述

以下代碼只是一個例子把組合子元素展示出來。 如果我連接去數(shù)據(jù)庫的話, 這種方法顯然行不通。因?yàn)槲覀儫o法確定有多少個組合多少個子。 大神們可否指點(diǎn)一下如何用 循環(huán)把它們展示出來? 例如用 For 循環(huán)。

adapter adapter; // BaseExpandableListAdapterExpandableListView expandableListView;List<String> category;HashMap<String,List<String>> item;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ex_listview); expandableListView=(ExpandableListView)findViewById(R.id.listview); display(); adapter=new adapter(this,category,item); expandableListView.setAdapter(adapter);}public void display(){ category=new ArrayList<String>(); item=new HashMap<String,List<String>>(); category.add('Western Food'); category.add('Chinese Food'); category.add('Japanese Food'); List<String> western_food = new ArrayList<String>(); western_food.add('Fried Chicken'); western_food.add('French Fries'); western_food.add('Beef Steak'); List<String> chinese_food = new ArrayList<String>(); chinese_food.add('Chicken Rice'); chinese_food.add('Duck Rice'); List<String> japanese_food = new ArrayList<String>(); japanese_food.add('Tapanyaki'); japanese_food.add('Takoyagi'); japanese_food.add('Sushi'); japanese_food.add('Lamian'); item.put(category.get(0), western_food); item.put(category.get(1), chinese_food); item.put(category.get(2), japanese_food);}

Android ExpandableListview 如何用循環(huán)把 組和子元素展示出來

問題解答

回答1:

無需知道有多少個組合與子,只要從數(shù)據(jù)庫中獲取的數(shù)據(jù)你能區(qū)別不同的組合與子所屬的組合就可以了。將數(shù)據(jù)放到相應(yīng)的存儲集合中,在通過設(shè)計Adapter就可以展示。

相關(guān)文章:
主站蜘蛛池模板: 昌乐县| 亳州市| 尼木县| 三门峡市| 桐乡市| 仙居县| 精河县| 湾仔区| 宣化县| 晋州市| 桓台县| 中卫市| 柞水县| 安福县| 土默特右旗| 尚义县| 松溪县| 咸阳市| 河南省| 德江县| 陈巴尔虎旗| 苗栗县| 林州市| 广元市| 宜兴市| 柘荣县| 遂宁市| 鄂州市| 洛隆县| 洛浦县| 文成县| 鹤岗市| 安顺市| 始兴县| 河池市| 冷水江市| 民权县| 孙吴县| 油尖旺区| 扶绥县| 海原县|