Open laatahzaan opened 5 years ago
Hi,
have you tried to get the longClickListener from the tableDataView instead of creating a new one?
OnLongClickListener longClickListener = tableDataView.getOnLongClickListener();
if( longClickListener != null ) {
longClickListener.onItemLongClick( tableDataView, view, index, id)
}
I have solved my problem. I forgot, that the focus is not given to item of the listview, but to editext. Thank you for the help.
public void focusToEditText(ViewGroup parent) {
for (int i = 0; i < parent.getChildCount(); i++) {
final View child = parent.getChildAt(i);
if (child instanceof ViewGroup) {
focusToEditText((ViewGroup) child);
} else {
if (child != null) {
if(child instanceof EditText) {
EditText editText = (EditText) child;
editText.setFocusable(true);
editText.requestFocus();
}
}
}
}
}
public void enterEditMode() {
if (tableDataView.getCount() > 0) {
int rowNumber = tableDataView.getCount() - 1;
tableDataView.setSelectionFromTop(rowNumber, 0);
tableDataView.invalidate();
new Handler().postDelayed(() -> {
View rowView = tableDataAdapter.getView(rowNumber, null, tableDataView);
AdapterView.OnItemLongClickListener onItemLongClickListener = tableDataView.getOnItemLongClickListener();
if (onItemLongClickListener != null) {
onItemLongClickListener.onItemLongClick(tableDataView, rowView, rowNumber, rowNumber);
}
new Handler().postDelayed(() -> {
focusToEditText(tableDataView);
}, 250);
}, 250);
}
}
Select last a row:
Add a new row:
Focus on the the new row:
The result is not expected, lost the blink cursor on last row when selected: https://drive.google.com/open?id=1beJ9QYTQu1Qe3iCqDKcRWcJ_-1IIZCAU
Expected result: https://drive.google.com/open?id=1D2ncW-T7gO8rny_2IDZTeCyWI1hS7DSH
How to resolved my problems?
Thanks.