【问题标题】:Deleting A Listview Item Makes Images Out Of Order删除 Listview 项目会使图像乱序
【发布时间】:2018-04-30 03:56:28
【问题描述】:

这就是我将图像和文本添加到列表视图的方式。

ArrayList<Integer> getList() {

//idImages = new ArrayList<>();


idImages.add(R.drawable.myhousech2image);
idImages.add(R.drawable.myhousech1image);
idImages.add(R.drawable.myhousech3image);

return idImages;

}

     ArrayList<String> getNameList() {

    //nameList = new ArrayList<>();



    nameList.add("Eat Snow");
    nameList.add("Stand In The Yard");
    nameList.add("Walk The Dog");

    return nameList;
}

我想使用它从列表中删除图像和文本。但是,这会导致应用程序在删除可绘制项目时由于和越界异常而崩溃。

        mDatabaseRef.addValueEventListener(new ValueEventListener() {



        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            FirebaseUser user = mAuth.getCurrentUser();


            if (dataSnapshot.child(user.getUid()).child("My House CH 1").exists()) {



                idImages.remove(R.drawable.myhousech2image);

                nameList.remove("Stand In The Yard");

                myAdapter.notifyDataSetChanged();


            }

我已经删除了图像,但是我不记得我使用了哪个代码。但它不起作用,因为图像不再与正确的文本对齐。另外我认为它会删除应该删除的图像下方的图像。

任何关于如何让它发挥作用的建议都很棒。谢谢!

【问题讨论】:

  • 创建一个包含名称及其相关图像的类。使用该类构建一个 ListView 适配器...
  • 另外,你可能打电话给list.remove(int index)而不是list.remove(Object item)

标签: android firebase listview imageview


【解决方案1】:
int INDEX=// index value of the Image
int INDEX2=// index value of the Name
idImages.remove(INDEX);
nameList.remove(INDEX2);

【讨论】:

  • 为您的答案添加一些解释。仅代码答案仅用于复制粘贴它没有帮助。
猜你喜欢
  • 2018-03-18
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
相关资源
最近更新 更多