[英]disabling edittext android using if else in view holder
請幫助我成功完成關於如何使用viewholder禁用editext或使用if and else
語句進行操作的另一種方式的噩夢
我有一個回收站視圖,其中列出了所有名稱及其消息。 (信使就好)。 回收者視圖以某種方式由名稱,消息和一個小標簽textview“客戶關閉”組成,如果他們要單擊由標簽“客戶關閉”組成的回收者視圖,則由於已關閉,因此將無法發送消息。 否則,所有由標簽“ customerclosed”組成的回收站視圖的editext都將設置為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
您只需要添加else標簽
if(customerInfo.isClosed){
message_editext.setEnabled(false);
} else {
message_editext.setEnabled(true);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.