我如何从编辑文本中获取最后一个字母并将其放入适配器

How can i get last letter from edit text and put it in adapter

我有一个删除按钮,用于删除 EditText 中的文本,EditText 的值是在 RecyclerView 中单击的项目。现在,当我从编辑文本中删除文本时,它会从适配器中消失。现在如何在单击删除后 return 将其返回到适配器?

@Override
public void onItemClick(View view, int position) {
    edit.setText(edit.getText() + adapter.getItem(position).toString().toUpperCase());
    edit.toString().toUpperCase();

    MediaPlayer  mediaPlayer2=MediaPlayer.create(Ridles.this,R.raw.zagonetkebutonklik);
    mediaPlayer2.start();
    suggestSource.remove(adapter.getItem(position));

    simpleArray = new String[suggestSource.size()];
    suggestSource.toArray(simpleArray);
    recyclerView = findViewById(R.id.recyclerView);
    int numberOfColumns = 5;
    recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
    adapter = new MyRecyclerViewAdapter(this, simpleArray);
    adapter.setClickListener(this);
    recyclerView.setAdapter(adapter);
    adapter.notifyItemRemoved(position);
    adapter.notifyItemChanged(position);
    adapter.notifyItemRangeChanged(position,suggestSource.size());
    lvl.setText("lvl: " +String.valueOf(curquestion));

}
public void obrisi(){
    String text=edit.getText().toString();
    if(text.length()>=1){
        edit.setText((text.substring(0, text.length() - 1)));
        edit.setVisibility(View.VISIBLE);

您可以从 EditText:

获取文本
String text = edit.getText().toString();

那么你可以这样得到最后一个字符:

String lastString = text.substring(string.length() - 1);

使用它从 EditText 中获取文本:

String text = edit.getText().toString();

然后像这样得到最后一个字母:

String lastL= text.substring(text.length() - 1);

然后设置值如下:

edit.setText(lastL);
edit.setVisibility(View.VISIBLE);