Android notifyDataSetChanged在BaseAdapter类内的AsyncTask中不工作

Android notifyDataSetChanged在BaseAdapter类内的AsyncTask中不工作,android,baseadapter,Android,Baseadapter,我已经使用BaseAdapter在listview中创建了一个广告列表,我想从列表中删除一个广告。要删除单个广告,我必须使用异步任务请求web api,因此我在onPostExecute方法中添加了notifyDataSetChanged()。ads已成功删除,但NotifyDatasetManaged不工作。下面给出了我的自定义BaseAdapter类。请帮助解决此问题 public class AdsListAdapter extends BaseAdapter{ priv

我已经使用BaseAdapter在listview中创建了一个广告列表,我想从列表中删除一个广告。要删除单个广告,我必须使用异步任务请求web api,因此我在onPostExecute方法中添加了notifyDataSetChanged()。ads已成功删除,但NotifyDatasetManaged不工作。下面给出了我的自定义BaseAdapter类。请帮助解决此问题

public class AdsListAdapter extends BaseAdapter{

        private Activity activity;
        ArrayList<String> title;
        ArrayList<Long> adsIds;
        SessionManager sessions;        
        AlertDialogManager alert = new AlertDialogManager();
        private static LayoutInflater inflater=null;     
        String MYTAG="AdLIst";

        long userID=0;


        public AdsListAdapter(Activity a,ArrayList<String> titlelist,ArrayList<Long> adsId,long userid) {
            activity = a;          
            title=titlelist;         
            adsIds=adsId;        
            userID=userid;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            sessions=new SessionManager(activity.getApplicationContext());
            imageLoader = new ImageLoader(activity.getApplicationContext());
        }


        public int getCount() {
            return title.size();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }


        public static class ViewHolder{
            public TextView titles,editicon,delicon;


        }

         @SuppressLint("NewApi") public View getView(int position, View convertView, ViewGroup parent) {
            final int id=position;
            View vi=convertView;
            ViewHolder holder;
            if(convertView==null){
                vi = inflater.inflate(R.layout.adscustomlist, null);
                holder = new ViewHolder();
                 holder.titles = (TextView) vi.findViewById(R.id.titles);
                holder.editicon= (TextView) vi.findViewById(R.id.editicon);              
                holder.delicon= (TextView) vi.findViewById(R.id.delicon);
                vi.setTag( holder );
            }
            else 
            { holder=(ViewHolder)vi.getTag(); }
            holder.titles.setText(title.get(position));
                holder.delicon.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {                           
                            new DeleteAd(userID,adsIds.get(id)).execute();
                        }
                    }); 


            return vi;
        }




        class DeleteAd extends  AsyncTask<String,Void,Void> 
        {
             AlertDialogManager alert = new AlertDialogManager();
                private String Error = null,Message=null; 
                   long UserID =0,AdId=0;
                   boolean Status=false;

                private ProgressDialog Dialog = new ProgressDialog(activity);           

                protected void onPreExecute() {                 
                        Dialog.setMessage("Loading ...");
                        Dialog.setCanceledOnTouchOutside(false);
                        Dialog.show();

                    }

                    public DeleteAd(long UserID,long AdId) {
                        this.UserID=UserID;
                        this.AdId=AdId;

                    }


            @Override
            protected Void doInBackground(String... arg0) {
                JSONObject json;                
                try {
                    json = new JSONObject(postDataAdDelete());
                    Message=json.getString("Message");
                    Status = json.getBoolean("Status");                 
                } catch (JSONException e) {                 
                    e.printStackTrace();
                }
                return null;
            }
              protected void onPostExecute(Void unused) {
                  Dialog.dismiss();
                  alert.showAlertDialog(activity, "Ad Delete", Message, Status);
                  notifyDataSetChanged();

            }
        }




}
public类AdsListAdapter扩展了BaseAdapter{
私人活动;
ArrayList标题;
阵列列表ADSID;
会话管理器会话;
AlertDialogManager alert=新建AlertDialogManager();
专用静态充气机=空;
字符串MYTAG=“AdLIst”;
长用户标识=0;
公共AdsListAdapter(活动a、ArrayList标题列表、ArrayList adsId、长用户ID){
活动=a;
标题=标题列表;
adsId=adsId;
userID=userID;
充气器=(LayoutInflater)activity.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
sessions=newsessionmanager(activity.getApplicationContext());
imageLoader=新的imageLoader(activity.getApplicationContext());
}
public int getCount(){
返回title.size();
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置){
返回位置;
}
公共静态类视图持有者{
公共文本视图标题、编辑图标、delicon;
}
@SuppressLint(“NewApi”)公共视图getView(int位置、视图转换视图、视图组父级){
最终int id=位置;
视图vi=转换视图;
视窗座;
if(convertView==null){
vi=充气机。充气(R.layout.adscustomlist,空);
holder=新的ViewHolder();
holder.titles=(TextView)vi.findViewById(R.id.titles);
holder.editicon=(TextView)vi.findViewById(R.id.editicon);
holder.delicon=(TextView)vi.findViewById(R.id.delicon);
vi.setTag(支架);
}
其他的
{holder=(ViewHolder)vi.getTag();}
holder.titles.setText(title.get(position));
holder.delicon.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
新建DeleteAd(userID,adsIds.get(id)).execute();
}
}); 
返回vi;
}
类DeleteAd扩展了异步任务
{
AlertDialogManager alert=新建AlertDialogManager();
私有字符串错误=null,消息=null;
长用户ID=0,AdId=0;
布尔状态=假;
private ProgressDialog=新建ProgressDialog(活动);
受保护的void onPreExecute(){
setMessage(“加载…”);
对话框。setCanceledOnTouchOutside(false);
Dialog.show();
}
公共DeleteAd(长用户ID,长AdId){
this.UserID=UserID;
这个。AdId=AdId;
}
@凌驾
受保护的Void doInBackground(字符串…arg0){
JSONObject json;
试一试{
json=新的JSONObject(postDataAddDelete());
Message=json.getString(“Message”);
Status=json.getBoolean(“Status”);
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(未使用的void){
Dialog.dismise();
alert.showAlertDialog(活动,“广告删除”、消息、状态);
notifyDataSetChanged();
}
}
}

必须删除列表标题中要删除的位置处的值。尝试删除标题。删除(位置)

您必须删除列表标题中要删除的位置的值。尝试title.remove(position)

AdsListAdapter=newadslistadapter(活动、ArrayList、ArrayList、long)//传递值
adapter.notifyDataSetChanged();
AdsListAdapter=新的AdsListAdapter(活动、ArrayList、ArrayList、long)//传递值
adapter.notifyDataSetChanged();

尝试像这样调用
notifyDataSetChanged()
方法

activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                        notifyDataSetChanged();
                }
            });

尝试像这样调用
notifyDataSetChanged()
方法

activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                        notifyDataSetChanged();
                }
            });