慕尼黑的夜晚無(wú)繁華
2022-07-14 10:37:54
我已經(jīng)實(shí)現(xiàn)了 expandablelistview 并且工作正常?,F(xiàn)在我想在每個(gè)子列表的末尾添加“加載更多”按鈕,這樣如果用戶單擊它,它將從服務(wù)器獲取更多項(xiàng)目。無(wú)論如何要這樣做,因?yàn)樵谒阉髁撕芏嘀笪艺也坏饺魏螙|西。非常感謝任何指導(dǎo)。這是我的自定義適配器:public class ExpandableListAdapterAssets extends BaseExpandableListAdapter implements Filterable {List<View> groupViews;ItemFilter mFilter;boolean showCheckBox;ArrayList<Asset> assetsToClaim;private Context _context;private List<AssetCategory> _listDataHeader; // header titles// child data in format of header title, child titleprivate HashMap<Integer, List<Asset>> _listDataChild;private RequestBackendHelper requestBackendHelper;public ExpandableListAdapterAssets(Context context, List<AssetCategory> listDataHeader, HashMap<Integer, List<Asset>> listChildData, boolean b){ this._context = context; this._listDataHeader = listDataHeader; this._listDataChild = listChildData; groupViews = new ArrayList<>(); showCheckBox = b; assetsToClaim = new ArrayList<>();}@Overridepublic Asset getChild(int groupPosition, int childPosition){ return this._listDataChild.get(this._listDataHeader.get(groupPosition).getId()) .get(childPosition);}public List<Asset> getChildList(int groupPosition){ return this._listDataChild.get(this._listDataHeader.get(groupPosition).getId());}@Overridepublic long getChildId(int groupPosition, int childPosition){ return childPosition;}@Overridepublic View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent){ final Asset assetChild = getChild(groupPosition, childPosition); if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_item, null); } TextView assetName = (TextView) convertView .findViewById(R.id.txt_asset_name); assetName.setText(assetChild.getName());
1 回答

慕斯王
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
您需要插入帶有自定義的“加載更多”按鈕BaseExpandableAdapter
。這個(gè)答案似乎是相關(guān)的,因?yàn)樗故玖巳绾翁峁﹥煞N不同類(lèi)型的子視圖。棘手的是,當(dāng)單擊“加載更多”按鈕時(shí),必須將其刪除,然后需要將新項(xiàng)目與底部的新“加載更多”按鈕連接在一起 - 然后是子適配器需要通知。它必須表現(xiàn)得像一個(gè)虛擬列表項(xiàng),其中getChildView()
提供當(dāng)前的childPosition
.
剛剛看到提供的代碼;使用 Volley,您很可能需要在第一次加載時(shí)少獲取一個(gè)項(xiàng)目,這樣適配器就不會(huì)由于添加了一個(gè)額外的虛擬項(xiàng)目而失去同步 - 或者至少在最后添加視圖類(lèi)型 2在將網(wǎng)絡(luò)請(qǐng)求添加到適配器之前。另一種選擇可能是讓getChildCount()
回報(bào)少一個(gè);在分頁(yè)時(shí)必須注意每種情況下的這個(gè)附加項(xiàng)目。
添加回答
舉報(bào)
0/150
提交
取消