Reputation: 85
I have a delete button which deletes text in an EditText, and the value of the EditText is the item clicked in a RecyclerView. Now when I delete text from edit text it disappears from the adapter. Now how can I return it back to adapter after clicking on delete?
@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);
Upvotes: 1
Views: 389
Reputation: 1957
Use this to get the text from EditText
:
String text = edit.getText().toString();
And get the last letter like this:
String lastL= text.substring(text.length() - 1);
Then set the value as follows:
edit.setText(lastL);
edit.setVisibility(View.VISIBLE);
Upvotes: 2
Reputation: 2412
You could just get the text from EditText
:
String text = edit.getText().toString();
Then you can get the last character like this:
String lastString = text.substring(string.length() - 1);
Upvotes: 0