我有一个3 editText的listView,当我在这些editText中显示数据时,我将editText设置为disabled,之后我创建了一个弹出菜单,我有编辑项目来修改数据,所以当我点击它时我启用了EDITTEXT。 我尝试了所有关于启用/禁用edittext的解决方案。但它没有工作。 :
我的屏幕lisTview:
来源:
public View getView(int position, View convertView, final ViewGroup parent) {
final int pos = position;
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.feed_item, null);
name = (EditText) convertView.findViewById(R.id.name_book_display);
statusMsg = (EditText) convertView.findViewById(R.id.desc_display);
prix = (EditText) convertView.findViewById(R.id.prix_display);
disableEditText(name);
disableEditText(statusMsg);
disableEditText(prix);
popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IconizedMenu popup = new IconizedMenu(parent.getContext(), view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.poupup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new IconizedMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.update_book:
enableEditText(name);
enableEditText(statusMsg);
enableEditText(prix);
updateBtn.setVisibility(View.VISIBLE);
return true;
case R.id.add_book_to_favoris:
return true;
case R.id.delete_book:
return true;
default:
return false;
}
}
}
);
popup.show();
}
});
return convertView;
}
private void disableEditText(EditText editText) {
editText.setFocusable(false);
editText.setEnabled(false);
editText.setCursorVisible(false);
editText.setKeyListener(null);
editText.setBackgroundColor(Color.TRANSPARENT);
}
private void enableEditText(EditText editText) {
editText.setFocusable(true);
editText.setEnabled(true);
editText.setCursorVisible(true);
editText.setKeyListener(listener);
}
答案 0 :(得分:1)
editText.setFocusable(true);
editText.setEnabled(true);
editText.setCursorVisible(true);
editText.setKeyListener(editText.getKeyListener());
答案 1 :(得分:0)
使用editText.setFocusableInTouchMode(true)
代替editText.setFocusable(true)
。
更新您的enableEditText()
方法,如下所示:
private void enableEditText(EditText editText) {
editText.setEnabled(true);
editText.setCursorVisible(true);
editText.setFocusableInTouchMode(true);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
}