Android – edit text cursor bug after closing the dialog box
I have a problem. I don't know what to call it or what causes it
I'm learning Android SQLite and starting to write a simple note taking application
The problem is that I have a custom dialog box for category selection. Before opening the dialog box, everything in the EditText field is fine, but after opening it, close it, and the text begins to be written. Just like creating multiple layers of the same text, the text cursor leaves the line behind each symbol. (see GIF of "bug demonstration" problem)
Has anyone seen anything like this? What could lead to this conversation?
Edit:
Therefore, this is the code to take action when you click the star to open the dialog box
starred.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(CreateNoteActivity.this);
View mView = getLayoutInflater().inflate(R.layout.dialog_category_select, null);
ListView categoryList = mView.findViewById(R.id.category_list);
Button cancelSelect = mView.findViewById(R.id.cancelSelect);
final Categorylistadapter adapter = new Categorylistadapter(CreateNoteActivity.this);
categoryList.setAdapter(adapter);
//get the data and append to a list
Cursor data = myDB.getCategories();
while(data.moveToNext()){
Category thisNote = new Category(data.getInt(0), data.getString(1), data.getString(2));
adapter.add(thisNote);
}
categoryList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
final Category selectedCategory = (Category) adapterView.getItemAtPosition(i);
int duration = Toast.LENGTH_SHORT;
String s = "Category celected: "+selectedCategory.getCategoryName();
Toast toast = Toast.makeText(context, s, duration);
toast.show();
}
});
builder.setView(mView);
final AlertDialog selectCategory = builder.create();
selectCategory.getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
selectCategory.show();
View decorView = getWindow().getDecorView();
decorView.setBackgroundResource(android.R.color.transparent);
int width = (int)(getResources().getDisplayMetrics().widthPixels*0.80);
int height = (int)(getResources().getDisplayMetrics().heightPixels*0.80);
selectCategory.getWindow().setLayout(width, height);
cancelSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectCategory.dismiss();
}
});
}
});
resolvent:
This answer may help you
Write this down after closing the dialog box
ediText = findViewById(R.id.edit_text);
editText.setSelection(editText.getText().length);
Basically, using the above logic, the cursor will not point to the first character of EditText when the dialog box is closed