HOW TO CALLING A FRAGMNET INSIDE ITS LISTVIEW ADAPTER?

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
 1069  View(s)
Ratings:
Rate this:
I have a Fragment which has a ListView inside it , in each row of my ListView i have a delete Button which works perfectly, what i need is to refresh my ListView to show the updated data. my question is how can i refresh my ListView inside its Adapter. this is my Adapter:

public class BrowserBannedListViewAdapter extends BaseAdapter {
Context mContext;
private static List<BrowserBannedSites> listUrlForAdapter;
AppSQLiteHelper db;

public BrowserBannedListViewAdapter(Context c, List<BrowserBannedSites> urls) {
    mContext = c;
    listUrlForAdapter = urls;
}
public static void main(String[] args) {
    // TODO Auto-generated method stub
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return listUrlForAdapter.size();
}
@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}
static class ViewHolder {
    TextView text;
    ImageView icon;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    LayoutInflater li = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = li.inflate(R.layout.row_fragment_browser_url, null);
        viewHolder = new ViewHolder();
        viewHolder.text = (TextView) convertView
                .findViewById(R.id.tv_fragment_browser_url_name);
        viewHolder.icon = (ImageView) convertView
                .findViewById(R.id.iv_fragment_browser_delete);
        viewHolder.icon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                        db=new AppSQLiteHelper(mContext);
                int tempID =listUrlForAdapter.get(position).get_Id();
                db.deleteBannedSites(tempID);
  //******************** here is where i want to refresh my listview
            }
        });
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
      viewHolder.text.setText(listUrlForAdapter.get(position).get_browserBannedSitesAddress());
    return convertView;
}
}
  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to calling a fragmnet inside its ListView Adapter?

    Only deleting from database will not working. you need to delete from List too.


    deleteButton.setOnClickListener(new OnClickListener(){
       public void onClick(View v){
          .........
          listUrlForAdapter.remove(position); // position is the position of the custom view in the list 
          notifyDataSetChanged();
        }
    }

      Modified On Apr-06-2018 12:10:39 AM
  1. Pawan Shukla

    Post:36

    Points:260
    Re: How to calling a fragmnet inside its ListView Adapter?

    change first the List of your data and You can directly call notifyDataSetChanged();


    @Override
            public void onClick(View v) {
                        db=new AppSQLiteHelper(mContext);
                int tempID =listUrlForAdapter.get(position).get_Id();
                db.deleteBannedSites(tempID);
         //******************** here is where i want to refresh my listview
                notifyDataSetChanged();
            }
        });

      Modified On Apr-06-2018 12:10:13 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!