Reputation: 11
Please help me in succeeding my nightmare regarding on how to disable the editext using viewholder or another way on how to do it using if and else
statement
I have a recycler view and it lists all names and their messages. (Messenger be like). Somehow the recycler view consists of name ,message and a small tag textview “customer closed” if they will going to click the recycler view that consist of tag “customer closed” they will not be able to send messages because its already closed. Otherwise all recycler view that consist of a tag “customer closed” it’s editext is set in to 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);
}
}
i got this error
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setEnabled(boolean)' on a null object reference
Upvotes: 1
Views: 598
Reputation: 5720
All you have to do is just add else tag
if(customerInfo.isClosed){
message_editext.setEnabled(false);
} else {
message_editext.setEnabled(true);
}
Upvotes: 2