为什么AsyncTask不在另一个AsynkTask的PostExecute方法中执行?

时间:2012-09-06 13:36:07

标签: android

我正在制作一个截面列表视图,其中第一部分是待处理请求列表,第二部分已经是朋友,在列表视图的第一部分有两个按钮接受和拒绝。 当我点击接受命中服务器并更改stautus,现在我的列表应该更新,第一部分接受列表应该显示在listview的第二部分的friendlist中。 我使用以下代码: -

public class EntryAdapter extends ArrayAdapter<Item> {

private Context context;
private List<Item> items;
private LayoutInflater objlayoutinflator;
private PostJobImageLoader objimageLoader;
private ConnectionFriendListModle objmodle=null;

public EntryAdapter(Context context,List<Item> items) {
    super(context, 0, items);
    this.context = context;
    this.items = items;
    objlayoutinflator = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    objimageLoader = new PostJobImageLoader(context.getApplicationContext());
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View myview = convertView;

    final Item objitem = items.get(position);
    if (objitem != null) {
        if (objitem.isSection()) {
            SectionItem objsection = (SectionItem) objitem;
            myview = objlayoutinflator.inflate(R.layout.listviewsection,
                    null);

            myview.setOnClickListener(null);
            myview.setOnLongClickListener(null);
            myview.setLongClickable(false);

            final TextView sectionView = (TextView) myview
                    .findViewById(R.id.txtsection);
            sectionView.setText(objsection.getTitle());
        } else {
            objmodle = (ConnectionFriendListModle) objitem;
            myview = objlayoutinflator.inflate(R.layout.connectionlistrow,
                    null);
            final TextView title = (TextView) myview
                    .findViewById(R.id.jobtitleinjobbidalert);
            final TextView subtitle = (TextView) myview
                    .findViewById(R.id.jobsubtitle);
            final ImageView objimageview = (ImageView) myview
                    .findViewById(R.id.user_image);
            final Button objaccept = (Button) myview
                    .findViewById(R.id.btnaccept);
            final Button objreject = (Button) myview
                    .findViewById(R.id.btnreject);

            if (objmodle.getStatus().equalsIgnoreCase("pending")) {
                objaccept.setVisibility(View.VISIBLE);
                objreject.setVisibility(View.VISIBLE);
                title.setText(objmodle.getUsername());
                subtitle.setText(objmodle.getName());
                String url = objmodle.getPicture();
                objimageLoader.DisplayImage(AppConstants.IMAGE_BASE_URL
                        + url, objimageview);
            } else {
                objaccept.setVisibility(View.INVISIBLE);
                objreject.setVisibility(View.INVISIBLE);
                title.setText(objmodle.getUsername());
                subtitle.setText(objmodle.getName());
                String url = objmodle.getPicture();
                objimageLoader.DisplayImage(AppConstants.IMAGE_BASE_URL+url, objimageview);
            }

            objaccept.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    new AcceptFriendRequest().execute(objmodle.getId(),"accepted");
                }
            });
            objreject.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v)
                {

                }
            });
        }
    }
    return myview;
}


 private class AcceptFriendRequest extends AsyncTask<String,Void,String>
    {
     ProgressDialog objprogress = new ProgressDialog(EntryAdapter.this.context);
     AppRequestHandler objApprequest = new AppRequestHandler();
     String objresponce="";
        @Override
        protected void onPreExecute() {
            objprogress.setMessage("Please Wait While Loading...");
            objprogress.show();
        }

        @Override
        protected String doInBackground(String... params) {
            objresponce = objApprequest.acceptRequest(params[0],params[1]);
            return objresponce;
        }

        @Override
        protected void onPostExecute(String result) {
            if(objprogress.isShowing())
            {
                objprogress.dismiss();
            }
            if(result.equals("0"))
            {
                SharedPreferences myPrefs = EntryAdapter.this.context.getSharedPreferences(
                        AppConstants.MYPREF, EntryAdapter.this.context.MODE_WORLD_READABLE);
                String userid = myPrefs.getString(AppConstants.USER_ID, "");

                                 //but when controll reach this line not execute this asynctask and niether update listview
                new GetAllConnectionDetail().equals("86");

            }
        }
    }

 private class GetAllConnectionDetail extends AsyncTask<String,Void,List<Item>>
    {
     ProgressDialog objprogress = new ProgressDialog(EntryAdapter.this.context);
     AppRequestHandler objApprequest = new AppRequestHandler();
     List<Item> objlistitem=null;
        @Override
        protected void onPreExecute() {
            objprogress.setMessage("Please Wait While Loading...");
            objprogress.show();
        }

        @Override
        protected List<Item> doInBackground(String... params) {
            objlistitem = objApprequest.connectionDetails(params[0]);
            return objlistitem;
        }

        @Override
        protected void onPostExecute(List<Item> result) {
            if(objprogress.isShowing())
            {
                objprogress.dismiss();
            }
              items.clear();
              items.addAll(result);
              notifyDataSetChanged();   
        }

    }

}

我是正确还是错,请任何人帮助我,为什么它不起作用......

1 个答案:

答案 0 :(得分:2)

您必须通过调用GetAllConnectionDetail方法启动execute任务,似乎您不这样做。