隐藏特定项目位置的textview表单ArrayAdaptor

时间:2018-10-16 13:38:29

标签: android listview android-arrayadapter

我想在 btn_chat_room_withdraw_offer 点击监听器上的 tv_description_of_tution 项内隐藏TextView。隐藏ArrayAdaptor中特定项目的TextView。这是我的聊天布局,我要隐藏TextView的特定项目该怎么做? 在项目中有多个textview,但是onclick我想隐藏一个TextView。

class ChatRoomAdapter extends ArrayAdapter<ChatMessage> {


    public ChatRoomAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        this.context = context;
        notifyDataSetChanged();
    }

    @Override
    public void add(ChatMessage object) {
        chatMessageList.add(object);
        super.add(object);
    }

    public int getCount() {
        return this.chatMessageList.size();
    }

    public ChatMessage getItem(int index) {
        return this.chatMessageList.get(index);
    }

    public View getView(final int position, final View convertView, ViewGroup parent) {

        final ChatMessage chatMessageObj = getItem(position);
        View row = convertView;
        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (chatMessageObj.left) {
            row = inflater.inflate(R.layout.chat_incoming_msg, parent, false);
            offer = "N";

        } else {
            row = inflater.inflate(R.layout.chat_outgoing_msg, parent, false);

        }
        /*Offered Message*/
        ll_offer = row.findViewById(R.id.ll_offer);
        ll_btns = row.findViewById(R.id.ll_btns);
        ll_withdrawn = row.findViewById(R.id.ll_withdrawn);

        btn_chat_room_withdraw_offer = row.findViewById(R.id.btn_chat_room_withdraw_offer);

        btn_chat_room_withdraw_offer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                sendData(chatMessageObj.msg_id, position);

            }
        });

        return row;
    }

}

1 个答案:

答案 0 :(得分:1)

您可以在ChatRoomAdapter

中使用方法
private void hideMessageAt(int position){
    chatMessageList.get(position).setHidden(true);
    notifyDataSetChanged();
}

但是您将需要向ChatMessage对象添加另一个字段。最后,在getView中执行以下操作

final ChatMessage chatMessageObj = getItem(position);
row.setVisibility(chatMessageObj.isHidden() == true ? View.GONE : View.VISIBLE);