Android:在点击可点击范围内的ListView行中显示特定小部件

时间:2016-08-10 11:28:42

标签: android listview

这里我的ListView连续几个小部件。

我需要获得小部件的正确位置并在适配器内管理它们的可见性。目前,它对last item的{​​{1}}可见。

我在这里也使用ListViewgetTag(),但它没有取得成功。

setTag()

1 个答案:

答案 0 :(得分:3)

对于此问题,您必须使用arrayList并在其中设置一个位置为

的标记
//Define arraylist globally
 private List<Boolean> requestionVisibleState;

//set a default value in constructor of adapter
 this.requestionVisibleState = new ArrayList<>(Arrays.asList(new Boolean[getCount()]));
    Collections.fill(this.requestionVisibleState, false);

//In getView after completing if else statement
 if (requestionVisibleState.get(position)) {
        holder.submitAnswerBtn.setVisibility(View.VISIBLE);
        holder.requestion_layout.setVisibility(View.VISIBLE);
    }
//And in `onClick` of your ClicableSpan
                    if (requestionVisibleState.get(position)) {
                        requestionVisibleState.set(position, false);
                    } else {
                        requestionVisibleState.set(position, true);
                    }
                    notifyDataSetChanged();

我希望它能为你效劳。

相关问题