I have a listview with custom base adapter which validate some items in listview. What i want is when i long click on item oflistview, a dialog should open stating "Yes" or "No" and when i tap on "Yes" it should delete that item from adapter.How can i do that.
Here is code of Adapter
private static final String TAG = CDealAppListingAdapter.class.getSimpleName();
private static final String DEAL_CODE = "DealCode";
private static final String HEADER_TEXT = "headerText";
private static final String LOGO_PATH = "logoPath";
private final Context m_Context;// declaring context variable
private final ArrayList<CDealAppDatastorage> s_oDataset;// declaring array list ariable
public CDealAppListingAdapter(Context m_Context, ArrayList<CDealAppDatastorage> mDataList) {
this.m_Context = m_Context;
s_oDataset = mDataList;
}
@Override
public int getCount() {// get total arraylist size
return s_oDataset.size();
}
@Override
public Object getItem(int position) {// get item position in array list
return s_oDataset.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressWarnings("deprecation")
@SuppressLint({"SetTextI18n", "InflateParams"})
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.deallisting_card_view, null);
viewHolder.m_Header = (TextView) convertView.findViewById(R.id.headingText);
viewHolder.m_DummyText = (TextView) convertView.findViewById(R.id.subHeadingText);
viewHolder.m_logoImage = (ImageView) convertView.findViewById(R.id.appImage);
viewHolder.m_getBtn = (Button) convertView.findViewById(R.id.getDealBtn);
viewHolder.mProgress = (ProgressBar) convertView.findViewById(R.id.progressBar3);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.m_getBtn.setOnClickListener(new View.OnClickListener() {// onclick getDeal Btn
@Override
public void onClick(View v) {//send to deal detail page onclick getDeal Btn
if (NetworkUtil.isConnected(m_Context)) {
Intent i = new Intent(v.getContext(), CDealAppListingDetails.class);
i.putExtra(DEAL_CODE, s_oDataset.get(position).getM_szsubHeaderText());// get deal code from deal data storage
i.putExtra(HEADER_TEXT, s_oDataset.get(position).getM_szHeaderText());// get deal name from deal dta storage
i.putExtra(LOGO_PATH, s_oDataset.get(position).getM_szLogoPath());
v.getContext().startActivity(i);
} else {
/*here I am getting error*/
CSnackBar.showSnackBarError(v, m_Context.getString(R.string.no_internet_connection), v.getContext());
}
}
});
CDealAppDatastorage m = s_oDataset.get(position);
viewHolder.m_Header.setText(m.getM_szHeaderText());
viewHolder.m_DummyText.setText(m.getM_szDetails());
viewHolder.m_getBtn.setText("GET " + m.getM_szDealValue() + " POINTS");// set deal button text
Picasso.with(m_Context).load(m.getM_szLogoPath()).into(viewHolder.m_logoImage, new Callback() {
@Override
public void onSuccess() {
Log.e(TAG, "OnSuccess Called::");
viewHolder.mProgress.setVisibility(View.INVISIBLE);
}
@Override
public void onError() {
Log.e(TAG, "OnError Called::");
}
});
return convertView;
}
private class ViewHolder {
public TextView m_Header, m_Subheader, m_DummyText;
public ImageView m_logoImage;
public Button m_getBtn;
public ProgressBar mProgress;
}
}
Sample code structure below;