This seems to have been asked in stackoverflow a bit before with no convincing answers for most questions. anyways, i attempt again. I have an Android App where am displaying a list where each row has an Edittext and Button component as seen below
The Edittext is non-editable when the view appears. I do this with the code below:
private void setNameAsEditable (View rowView, boolean setToEditable) {
EditText textView = (EditText) rowView
.findViewById(R.id.edittext_name);
textView.setFocusableInTouchMode(setToEditable);
textView.setFocusable(setToEditable);
ImageButton button = (ImageButton) rowView
.findViewById(R.id.button_save_name);
if ( setToEditable ) {
button.setVisibility (View.VISIBLE); // nullpointerexception here
} else {
button.setVisibility (View.GONE);
}
When I long-press, and setToEditable is true, it throws nullpointerexception in the line indicated above. it doesn't seem to find the button component. However, 'button.setVisibility (View.GONE);' is executed when setToEditable is false without any issue.
Can someone please help?