Скрыть форму просмотра текста ArrayAdaptor из позиции конкретного элемента - PullRequest
0 голосов
/ 16 октября 2018

Я хочу скрыть TextView, который находится внутри элемента tv_description_of_tution в прослушивателе btn_chat_room_withdraw_offer .Скрыть TextView от конкретного элемента в ArrayAdaptor.Это мой макет чата. Я хочу скрыть определенные элементы TextView, как это сделать?В элементе есть несколько текстовых представлений, но при нажатии я хочу скрыть один 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 голосов
/ 16 октября 2018

Вы можете иметь метод в 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);
...