2017-09-04 31 views
0

的指定行我可以隱藏特定行,但我回來到ListView活動將再次顯示特定行,我躲起來。這裏是我的代碼如下:如何隱藏特定行,當我點擊刪除列表視圖

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

回答

0

您需要刪除誰鏈接到適配器列表中的元素。

yourArrayList.remove(position); 
0

你需要通知使用notifyDataSetChanged()方法列表視圖。既然你用了,你可以從列表中(或)陣列刪除特定對象的幫助在setOnItemLongClickListener()的位置,那麼你就需要更新適配器列表,並通知適配器。希望這個Link是有幫助的。

在上述鏈路解釋了longClick除去數據和更新後的數據發送到適配器和通知列表是清楚的解釋。

0

你已經獲得該項目的位置,你點擊這裏:

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

現在從數據源(?ArrayList中)刪除項目:

list.remove(position); 

並刷新列表:

adapter.notifyDataSetChanged(); 
相關問題