从customerViewHolder禁用edittext是错误的

时间:2016-01-29 04:22:04

标签: java android fragment android-recyclerview android-viewholder

我有一个回收站视图,它列出了所有名称及其消息。 (信使如意)。不知何故,回收者视图包含名称,消息和小标签textview“客户关闭”,如果他们将要点击包含标签“客户关闭”的回收者视图,他们将无法发送消息,因为它已经关闭。否则,所有包含“客户已关闭”标签的回收商视图都会被设置为false。

public void bind(final Account account, final FirebaseChat chat) {
    itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = itemView.getContext();
            if (context instanceof NavigationActivity) {
                final Activity activity = (Activity) context;

                final Intent intent = new Intent(itemView.getContext(), myChat.class);
                intent.putExtra(ChatActivity.KEY_NEW, false);
                intent.putExtra(ChatActivity.KEY_ACCOUNT, account);
                intent.putExtra(ChatActivity.KEY_CHAT, chat);

                activity.startActivity(intent);
            }
        }
    });

    cName.setText(chat.getName());
    cName.setTypeface(chat.getReadCount() < chat.getNumMessages() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
    cTextDate.setText(getFormattedDate(chat.getLastTime()));
    cTextMessage.setText(chat.getLastMessage());
    cTextMessage.setTypeface(chat.getReadCount() < chat.getNumMessages() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);



}




public void bind(final Account account, final FirebaseChatInfo customerInfo) {
    itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = itemView.getContext();
            if (context instanceof NavigationActivity) {
                final Activity activity = (Activity) context;
                final Intent intent = new Intent(itemView.getContext(), myChat.class);
                intent.putExtra(ChatActivity.KEY_NEW, false);
                intent.putExtra(ChatActivity.KEY_ACCOUNT, account);
                intent.putExtra(ChatActivity.KEY_CHAT_INFO, customerInfo);

                activity.startActivity(intent);
            }
        }
    });




    cName.setText(chatInfo.getName());
    cName.setTypeface(chatInfo.isLastVisitorMessaged() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
    cTextDate.setText(getFormattedDate(chatInfo.getLastTime()));
    cTextMessage.setText(chatInfo.getLastMessage());
    cMessage.setTypeface(chatInfo.isLastVisitorMessaged() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);

    this.shoptag = (TextView) itemView.findViewById(R.id.shoptag);
    shoptag.setText(chatInfo.getShop_id());
    this.customerclosed = (TextView) itemView.findViewById(R.id.customer_closed);
    this.customerclosed.setVisibility(chatInfo.isClosed() ? View.GONE : View.VISIBLE);
    this.message_editext = (EditText)itemView.findViewById(R.id.message_editext);

    message_text.setEnabled(!chatInfo.isClosed());

    if(customerInfo.isClosed())
    {

        message_text.setEnabled(false);


    }else {

        message_textt.setEnabled(true);
    }

}

我收到了这个错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setEnabled(boolean)' on a null object reference

1 个答案:

答案 0 :(得分:0)

 this.message_editext = (EditText)itemView.findViewById(R.id.message_editext);

   message_text.setEnabled(!chatInfo.isClosed());

    if(customerInfo.isClosed())
    { 

        message_editext.setEnabled(false); 


    }else { 

        message_editext.setEnabled(true); 
    }