I have a list that I saved in sharedpreferences I want to delete an item from the listview when the user longclicks so on the long click the app prompts you with a question to delete or not when you confirm it deletes it. This works but when i come back to the activity the list still contains that item that has been deleted
This is the code for the onCreateView. tinyDB is sharedprefrences.Thank you
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tab_secondsemester, container, false);
btnAddNew = (Button)rootView.findViewById(R.id.btnAddNewYearOneSecondSemester);
listView = (ListView)rootView.findViewById(R.id.listViewSubjectsMyCoursesSecondSemester);
tinyDB = new TinyDB(getContext());
storedList = new ArrayList<>(tinyDB.getListString("storedList"));
generalList = new ArrayList<>();
spinnerValues = new ArrayList<>();
getActivity().setTitle("Year One");
setHasOptionsMenu(true);
btnAddNew.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext(),R.style.DialogeTheme);
// Setting Dialog Title
alertDialog.setTitle("Add new");
// Setting Dialog Message
String getUsername = tinyDB.getString("Username");
alertDialog.setMessage("Hello "+ getUsername + ", please write the new subject");
final EditText input = new EditText(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
input.setTextColor(Color.parseColor("#f06292"));
alertDialog.setView(input);
alertDialog.setPositiveButton("Add", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
String getSubjectInput = input.getText().toString();
storedList.add(getSubjectInput);
tinyDB.putListString("storedList", storedList);
arrayAdapter.notifyDataSetChanged();
}
});
alertDialog.setNegativeButton("CANCEL",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.create();
alertDialog.show();
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
new SweetAlertDialog(getContext(), SweetAlertDialog.WARNING_TYPE)
.setTitleText("Delete")
.setContentText("Are you sure you want to delete this course")
.setConfirmText("YES")
.setCancelText("NO")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
#Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
storedList.remove(i);
arrayAdapter.notifyDataSetChanged();
tinyDB.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
arrayAdapter.notifyDataSetChanged();
}
});
sweetAlertDialog.dismiss();
}
})
.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
#Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
sweetAlertDialog.dismiss();
}
})
.show();
return true;
}
});
arrayAdapter = new CustomListAdapter(getContext(),storedList);
listView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();
return rootView;
}
Use this when the user deletes it
public void removeAt(int position) {
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataSet.size());
}
mDataset is the array/list in which you save all the data for the adapter
Related
i have some problems with updating fragment view after item deleted. So i have one fragment which one showing all items added from another activity. And when im trying to delete item it's not updating view so i should restart fragment to see updated fragment.
There is my fragment
public class MyGarageFragment extends Fragment {
FloatingActionButton fab;
RecyclerView mRecyclerView;
DatabaseHelper databaseHelper;
RVAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_my_garage, null);
mRecyclerView = v.findViewById(R.id.recyclerView);
databaseHelper = new DatabaseHelper(getContext());
showRecord();
fab = v.findViewById(R.id.addFabButton);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// startActivity(new Intent(getContext(), AddRecordActivity.class));
Intent intent = new Intent(getContext(), AddAutoActivity.class);
intent.putExtra("editMode",false);
startActivity(intent);
}
});
return v;
}
private void showRecord() {
adapter = new RVAdapter(getContext(),databaseHelper.getAllData(Constants.C_ADD_TIMESTAMP + " DESC"));
mRecyclerView.setAdapter(adapter);
}
#Override
public void onResume(){
super.onResume();
showRecord();
}
also my Recyclerview Adapter
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.Holder> {
private Context context;
private ArrayList<Model> arrayList;
DatabaseHelper databaseHelper;
#NonNull
#Override
public Holder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_my_garage,parent,false);
return new Holder(view);
}
public RVAdapter(Context context, ArrayList<Model> arrayList) {
this.context = context;
this.arrayList = arrayList;
databaseHelper = new DatabaseHelper(context);
}
#Override
public void onBindViewHolder(#NonNull Holder holder, int position) {
Model model = arrayList.get(position);
String id = model.getId();
String image = model.getImage();
String name = model.getName();
String age = model.getAge();
String phone = model.getPhone();
String addTimeStamp = model.getAddTimeStamp();
String updateTimeStamp = model.getUpdateTimeStamp();
holder.profileIv.setImageURI(Uri.parse(image));
holder.name.setText(name);
holder.age.setText(age);
holder.phone.setText(phone);
holder.editButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(context, holder.editButton);
popupMenu.inflate(R.menu.popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit:
editDialog(
""+position,
""+id,
""+name,
""+age,
""+phone,
""+image,
""+addTimeStamp,
""+updateTimeStamp
);
break;
case R.id.action_delete:
deleteDialog(""+id);
break;
default:
break;
}
return false;
}
});
popupMenu.show();
}
});
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context,"item " + id, Toast.LENGTH_SHORT).show();
}
});
}
private void deleteDialog(String id) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Delete");
builder.setMessage("Are you sure?");
builder.setCancelable(false);
builder.setIcon(R.drawable.ic_baseline_delete_24);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
databaseHelper.deleteInfo(id);
((MyGarageFragment)context).onResume();
Toast.makeText(context, "Delete Success!", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.create().show();
}
private void editDialog(String position, String id, String name, String age, String phone, String image, String addTimeStamp, String updateTimeStamp) {
Intent intent = new Intent(context, EditAutoActivity.class);
intent.putExtra("ID",id);
intent.putExtra("NAME",name);
intent.putExtra("AGE",age);
intent.putExtra("PHONE",phone);
intent.putExtra("IMAGE",image);
intent.putExtra("ADD_TIMESTAMP",addTimeStamp);
intent.putExtra("UPDATE_TIMESTAMP",updateTimeStamp);
intent.putExtra("editMode",true);
context.startActivity(intent);
}
#Override
public int getItemCount() {
return arrayList.size();
}
class Holder extends RecyclerView.ViewHolder {
ImageView profileIv;
TextView name,age,phone;
ImageView editButton;
public Holder (#NonNull View itemView){
super(itemView);
profileIv = itemView.findViewById(R.id.profileIv);
name = itemView.findViewById(R.id.name);
age = itemView.findViewById(R.id.age);
phone = itemView.findViewById(R.id.phone);
editButton = itemView.findViewById(R.id.editBtn);
}
}
}
so what should i do in deleteDialog to delete cardview item and refresh ui?
private void deleteDialog(String id) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Delete");
builder.setMessage("Are you sure?");
builder.setCancelable(false);
builder.setIcon(R.drawable.ic_baseline_delete_24);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
databaseHelper.deleteInfo(id);
((MyGarageFragment)context).onResume();
Toast.makeText(context, "Delete Success!", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.create().show();
}
I'm making a todo app and when an item is marked as finished an image should be displayed in front of the list item. But images are not visible in the list view even if the item status in the database is changed as finished.
This is my adapter class.
public class ToDoAdapter extends ArrayAdapter {
private Context context;
private int resource;
List<ToDoModel> todos;
public ToDoAdapter(#NonNull Context context, int resource, #NonNull List<ToDoModel> objects) {
super(context, resource, objects);
this.context = context;
this.resource = resource;
this.todos = objects;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
//Inflate card view
LayoutInflater inflater = LayoutInflater.from(context);
View row = inflater.inflate(resource, parent, false);
TextView title = row.findViewById(R.id.title);
TextView description = row.findViewById(R.id.txtDescription);
ImageView img = (ImageView)row.findViewById(R.id.img_done);
img.setVisibility(View.VISIBLE);
//Set data in card view
ToDoModel todo = todos.get(position);
title.setText(todo.getTitle());
description.setText(todo.getDescription());
//Show done image
if(todo.getFinished() > 0){
img.setVisibility(View.VISIBLE);
}
return row;
}
}
This is MainActivity.
public class MainActivity extends AppCompatActivity {
private ListView todoList;
private TextView countTxt;
private Button addTodo;
private List<ToDoModel> toDos;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
todoList = (ListView)findViewById(R.id.listViewToDo);
countTxt = (TextView)findViewById(R.id.txtCount);
addTodo = (Button)findViewById(R.id.btnAdd);
toDos = new ArrayList<>();
addTodo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Go to next activity
startActivity(new Intent(getApplicationContext(), AddToDO.class));
}
});
}
#Override
protected void onResume() {
super.onResume();
DBHandler dbh = new DBHandler(getApplicationContext());
//Set count
int count = dbh.getCountTODO();
countTxt.setText("You have " + count + " TODOs");
//Save list
toDos = dbh.getAllToDos();
//Set adapter to list
ToDoAdapter toDoAdapter = new ToDoAdapter(getApplicationContext(), R.layout.todo_cardview, toDos);
todoList.setAdapter(toDoAdapter);
//Add click listener to list element
todoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Get clicked item
ToDoModel todo = toDos.get(position);
//Dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(todo.getTitle());
builder.setMessage(todo.getDescription());
//Buttons
builder.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dbh.deleteItem(todo.getId());
Toast.makeText(getApplicationContext(), "ToDo Deleted", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
});
builder.setPositiveButton("Finished", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
long time = System.currentTimeMillis();
//Update status
dbh.updateFinished(todo.getId(), time);
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
});
builder.setNeutralButton("Edit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(MainActivity.this, AddToDO.class);
intent.putExtra("id", todo.getId());
intent.putExtra("title", todo.getTitle());
intent.putExtra("description", todo.getDescription());
intent.putExtra("finished", todo.getFinished());
startActivity(intent);
}
});
builder.show();
}
});
}
}
Use Glide or Picasso Library to Displaying Image with any other Shape.
Glide Example:
Glide.with(mContext).load(responseList.getLogoUrl()).apply(RequestOptions.circleCropTransform()).into(holder.imageName);
Picasso Example:
Picasso.get().load(clsobjname.getLogoUrl())
.into(viewHolder.imagename);
I have a list of items that are displayed in a recylcerview in my adapter class i implmented a onlongclick method, when used it opens up a new alertdialog, when i press on the selected item in the alterdialog im calling updateList() function that is supposed to update the selected item the problem is this only works for the first item displayed in my list, so in exmaple if i pressed the 10th item on the list said item wont update.
Update function
public boolean updateList(long rowId, String stanje) {
ContentValues newValues = new ContentValues();
newValues.put(TABELA_STOLPEC_STANJE,stanje);
return db.update(TABELA_IME,newValues,TABELA_STOLPEC_ID+"="+rowId,null)>0;
}
OnlongClickListener this method is in my fragment class.
mmAdapter.setOnLongClick(new ToDoRecyclerViewAdapter.OnLongClickListener_() {
#Override
public void onLongClick(long i,String item) {
if(item.equals("doing")) {
boolean update_1 = db.updateList(i, item);
if(update_1) {
android.support.v4.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(TodoFragment.this).attach(TodoFragment.this).commit();
Toast.makeText(getContext(), "Dodano v bazo.!", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getContext(), "Prislo je do napake!", Toast.LENGTH_SHORT).show();
}
}
}
});
onlongclicklistener implementation in my adapter class
holder.mView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(final View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(v.getContext());
CharSequence meni[] = new CharSequence[] {"DOING"};
adb.setItems(meni, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if(i == 0) {
mValues.get(i).setStanje("doing");
clickLinster_.onLongClick(mValues.get(position).getId_(),mValues.get(position).getStanje());
}
}
});
AlertDialog alertDialog = adb.create();
alertDialog.setCancelable(true);
alertDialog.show();
return true;
}
});
public interface OnLongClickListener_ {
void onLongClick(long i, String item);
}
The reason is simple, you are updating wrong row with index, correct solution:
#Override
public void onBindViewHolder(#NonNull final CustomViewHolder holder, int position) {
//Rest of onBindViewHolder code
holder.mView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(final View v) {
final int pos = holder.getAdapterPosition();
AlertDialog.Builder adb = new AlertDialog.Builder(v.getContext());
CharSequence meni[] = new CharSequence[] {"DOING"};
adb.setItems(meni, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if(i == 0) {
mValues.get(pos).setStanje("doing");
clickLinster_.onLongClick(mValues.get(pos).getId_(),mValues.get(pos).getStanje());
}
}
});
AlertDialog alertDialog = adb.create();
alertDialog.setCancelable(true);
alertDialog.show();
return true;
}
});
}
I'm currently using the Parse API for Android, and I currently have a Array of Strings in my application. I currently have a ListView with all of my Strings. Inside my app inside the ListView itself I have implemented a setOnItemLongClickListener with a Dialog. I want to delete a the selected ListView item's string from Parse.
Image of the Database Row
NotesFragment.java
public class NotesFragment extends Fragment {
ParseUser user;
ListView notesList;
private FloatingActionButton FAB;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_notes, container, false);
notesList = (ListView) rootView.findViewById(R.id.lv_contact);
user = ParseUser.getCurrentUser();
FAB = (FloatingActionButton) rootView.findViewById(R.id.fab);
FAB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), AddNoteActivity.class);
getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
startActivity(intent);
}
});
final ArrayList<ParseObject> list1 = (ArrayList) user.getList("notes");
ArrayAdapter<ParseObject> arrayAdapter;
arrayAdapter = new ArrayAdapter<ParseObject>(getContext(), android.R.layout.simple_list_item_1, list1);
RelativeLayout emptyView = (RelativeLayout) rootView.findViewById(R.id.empty);
if (list1 == null) {
emptyView.setVisibility(View.VISIBLE);
} else {
notesList.setAdapter(arrayAdapter);
emptyView.setVisibility(View.INVISIBLE);
}
notesList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
new AlertDialog.Builder(getContext())
.setTitle("Are you sure you want to Delete?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ArrayList<String> toRemove = new ArrayList<>();
toRemove.add("Hey");
ParseUser.getCurrentUser().removeAll("checklistDat", toRemove);
ParseUser.getCurrentUser().saveInBackground();
ParseUser.getCurrentUser().deleteInBackground();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
return true;
}
});
return rootView;
}
}
I was able to fix this by doing this
NotesFragment.java
public class NotesFragment extends Fragment {
ParseUser user;
ListView notesList;
ProgressBar mPB;
private FloatingActionButton FAB;
ArrayList<ParseObject> list1 = (ArrayList) ParseUser.getCurrentUser().getList("notes");
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_notes, container, false);
mPB = (ProgressBar) rootView.findViewById(R.id.progress_bar);
mPB.setVisibility(View.VISIBLE);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mPB.setVisibility(View.GONE);
}
}, 3500);
notesList = (ListView) rootView.findViewById(R.id.lv_contact);
user = ParseUser.getCurrentUser();
FAB = (FloatingActionButton) rootView.findViewById(R.id.fab);
FAB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), AddNoteActivity.class);
getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
startActivity(intent);
}
});
final ArrayAdapter<ParseObject> arrayAdapter;
arrayAdapter = new ArrayAdapter<ParseObject>(getContext(), android.R.layout.simple_list_item_1, list1);
final RelativeLayout emptyView = (RelativeLayout) rootView.findViewById(R.id.empty);
if (list1 == null) {
emptyView.setVisibility(View.VISIBLE);
mPB.setVisibility(View.GONE);
} else {
notesList.setAdapter(arrayAdapter);
emptyView.setVisibility(View.INVISIBLE);
}
notesList.setLongClickable(true);
notesList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
new android.app.AlertDialog.Builder(getContext())
.setTitle("Delete?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
list1.remove(position);
ParseUser.getCurrentUser().remove("notes");
ParseUser.getCurrentUser().put("notes", list1);
ParseUser.getCurrentUser().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Toast.makeText(getContext(), "Deleted", Toast.LENGTH_SHORT).show();
if (list1.toString().equals("[]")) {
emptyView.setVisibility(View.VISIBLE);
mPB.setVisibility(View.GONE);
} else {
notesList.setAdapter(arrayAdapter);
emptyView.setVisibility(View.INVISIBLE);
}
}
});
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
return true;
}
});
return rootView;
}
}
I'm making a simple to do list and I want to be able to click on the item and enter a new text which will then replace the text of the TextView in that cell. I've got the dialogAlert working, I just don't know how to grab the cell's TextView and change it
This is what the Activity looks like,
public class MainActivity extends AppCompatActivity {
private ListDataSource ds;
private ListView listViewToDo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Context context = this;
Log.d("MainActivity","Attempting to create data source");
try {
ds = new ListDataSource();
}
catch(Exception e)
{
e.printStackTrace();
Log.d("MainActivity","Failed to create data source");
}
Log.d("Main Activity","Attempting to link empty list view to on screen view");
listViewToDo = (ListView)findViewById(R.id.listOfLists);
Log.d("Main Activity","Views linked, Attempting to set adapter to listView");
listViewToDo.setAdapter(new ListDataSourceAdapter(this, ds));
Log.d("Main Activity", "Successfully set Adapter");
// add button listener
listViewToDo.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id)
{
AlertDialog.Builder editItem = new AlertDialog.Builder(context);
final EditText edittext = new EditText(context);
editItem.setTitle("Change Item");
editItem
.setMessage("Set new todo item")
.setView(edittext)
.setCancelable(false)
.setPositiveButton("Submit", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//what do I put here?
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alertDialog = editItem.create();
alertDialog.show();
}
});
}
}
ds.remove(position);
ds.add(position,edittext.getText().toString().trim())
ListDataSourceAdapter adapter = new ListDataSourceAdapter(this, ds)
listViewToDo.setAdapter(adapter );
adapter.notifDataSetChanged();