0

I can hide the specific row, but i come back to the listview activity it will show again the specific row that I hide. Here is my code in below:

listView.setLongClickable(true);
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            public boolean onItemLongClick(AdapterView<?> parent, final View v, final int position, long id) {
                //Do your tasks here
                textViewID = (TextView) v.findViewById(R.id.text_customerid);
                custid = textViewID.getText().toString();
                AlertDialog.Builder alert = new AlertDialog.Builder(
                        TableRecordActivity.this);
                alert.setTitle("Alert!!");
                alert.setMessage("Are you sure to delete record");
                alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //databaseHelper = new DatabaseHelper(getApplicationContext());
                    //sqLiteDatabase=databaseHelper.getReadableDatabase();
                    //databaseHelper.deleteCustomerInformation(custid,sqLiteDatabase);
                    LinearLayout parentLayout = (LinearLayout) v.findViewById(R.id.linearLayout);
                    parentLayout.setVisibility(View.GONE);
                    //Intent intent = new Intent(getApplication(),TableRecordActivity.class);
                    //intent.putExtra("user_id2",user_id2);
                    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    //startActivity(intent);
                    Toast.makeText(getApplicationContext(),"Customer deleted",Toast.LENGTH_LONG).show();
                    dialog.dismiss();

                }
            });
            alert.setNegativeButton("NO", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }
            });

            alert.show();

            return true;
        }
    });
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Xuezheng Low
  • 65
  • 1
  • 7

3 Answers3

0

You need to delete the element in the List who is linked to the adapter.

yourArrayList.remove(position);
Vodet
  • 1,491
  • 1
  • 18
  • 36
0

you need to notify the list view using notifyDataSetChanged() method. Since you got the position in the setOnItemLongClickListener() with the help of that you can remove that particular object from the list (or) array, then you need to update the list in the adapter and notify the adapter. Hopefully this Link is helpful.

In the above link explains removing the data on longClick and sending the updated data to the adapter and notifying the list is clearly explained.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jeevanandhan
  • 1,073
  • 10
  • 18
0

You already get the position of the item you clicked on, here :

public boolean onItemLongClick(AdapterView<?> parent, final View v, final int position, long id) {
}

Now remove the item from the data-source (ArrayList?):

list.remove( position );

And refresh the list:

adapter.notifyDataSetChanged();
RonTLV
  • 2,376
  • 2
  • 24
  • 38