gpt4 book ai didi

android - 对话框关闭后的 EditText 光标错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:17:47 24 4
gpt4 key购买 nike

bug demo

我遇到了一个问题。不知道该怎么调用它,或者是什么原因造成的

我正在学习 Android SQLite 并接受培训,开始制作一个简单的笔记应用。

问题是我有一个用于类别选择的自定义对话框,在打开对话框之前,EditText 字段中的一切都很好,但是在打开并关闭它之后,文本开始重写,就像创建相同文本的多层和文本光标在每个符号后留下一行。 (请参阅问题的“错误演示”GIF)

有没有人见过这样的事情?是什么导致了这个,对话框?

编辑:

所以这是点击星标打开对话框时执行操作的代码

 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();
}
});

}
});

最佳答案

这个答案可能对你有帮助

对话框关闭后写这个

ediText = findViewById(R.id.edit_text);

editText.setSelection(editText.getText().length);

基本上使用上面的逻辑,光标不会指向 dialog close 上的 editText 的第一个字符

关于android - 对话框关闭后的 EditText 光标错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50948486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com