亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

網格圖像適配器排序

網格圖像適配器排序

江戶川亂折騰 2021-10-06 10:49:54
我用圖像構建了一些 gridView,一切正常。我有一組圖像,我可以點擊它們中的每一個,然后根據需要繼續進行另一項活動。問題是 - 當我向適配器添加新圖像時 - 它被添加到堆棧的末尾。我怎樣才能重新排列圖像的顯示從新到舊而不是像現在一樣從舊到新。(我自己做了一些事情(正如你在評論中看到的),它的顯示就像我想要的,但是當我點擊圖片時,我得到了錯誤的圖片):final ArrayList<String> imgString = new ArrayList<>();        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();        Query query = reference                .child("user_photos")                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());        query.addListenerForSingleValueEvent(new ValueEventListener() {            @Override            public void onDataChange(DataSnapshot dataSnapshot) {                for ( DataSnapshot singleSnapshot :  dataSnapshot.getChildren()){                    // photos.add(singleSnapshot.getValue(Photo.class));                    imgString.add(singleSnapshot.child("postimage").getValue().toString());                }                //setup our image grid                int gridWidth = getResources().getDisplayMetrics().widthPixels;                int imageWidth = gridWidth/NUM_GRID_COLUMNS;                gridView.setColumnWidth(imageWidth);                final ArrayList<String> imgUrls = new ArrayList<String>();                for(int i = 0; i < imgString.size(); i++){                    imgUrls.add(imgString.get(i));//                for(int i = imgString.size()-1; i >=0 ; i--){//                    imgUrls.add(imgString.get(i));                }                GridImageAdapter adapter = new GridImageAdapter(ProfileActivity.this,R.layout.layout_grid_imageview,"", imgUrls);                gridView.setAdapter(adapter);
查看完整描述

1 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

@Override

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    PostKey=imgString.get(i);//here i is the position of the view in the adapter.

正如你所做的那樣:


for(int i = imgString.size()-1; i >=0 ; i--){

              imgUrls.add(imgString.get(i));//imgUrls.get(0) stored imgString.get(imgString.size()-1)

當您單擊 0 位置的項目時,其 imgUrls 不指向imgString.get(0),而是imgString.get(imgString.size()-1)。


編輯:試試這個:


PostKey=imgString.get(imgString.size()-1-i);


查看完整回答
反對 回復 2021-10-06
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號