1

我有一个BaseAdapter,我有一个Button。当用户单击该按钮时,我需要调用 aService并且需要将数据设置为该按钮onpostExecute()

public class MenuTagsAdapter extends BaseAdapter {
        View v;

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return BaseApp.getTagsAroundMeList().size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            v = layoutInflater.inflate(R.layout.menutaglistitem, null);

            TextView textViewName = (TextView) v
                    .findViewById(R.id.textViewName);
            final Button buttonAction = (Button) v
                    .findViewById(R.id.buttonAction);

            textViewName.setText("#"
                    + BaseApp.getTagsAroundMeList().get(position).name);

            buttonAction
                    .setText(BaseApp.getTagsAroundMeList().get(position).action);

            buttonAction.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    if (buttonAction.getText().toString()
                            .equalsIgnoreCase("follow")) {

                        buttonAction.setBackgroundResource(R.drawable.followbutton);

                        if (appUtils.getNetworkInfo(AmgonnaHome.this)) {

                            new FollowInterestAsyTask().execute();
                        } else {
                            NetworkDialogClass.createDAlertDialog(
                                    AmgonnaHome.this,
                                    getString(R.string.network_error));
                        }

                    } else {

                        buttonAction.setBackgroundResource(R.drawable.unfollowbutton);

                        if (appUtils.getNetworkInfo(AmgonnaHome.this)) {

                            new UnfollowInterestAsyTask().execute();
                        } else {
                            NetworkDialogClass.createDAlertDialog(
                                    AmgonnaHome.this,
                                    getString(R.string.network_error));
                        }

                    }

                }
            });

            return v;
        }

    }





public class FollowInterestAsyTask extends AsyncTask<Void, Void, Void> {
        boolean progressDialogStatus = true;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(AmgonnaHome.this,
                    "Please Wait", "Connecting to Server");
            progressDialog.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressDialogStatus = false;

                }
            });
        }

        @Override
        protected Void doInBackground(Void... params) {
            TaskUrl = BaseApp.baseUrl + BaseApp.followInterest;

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("user_id=" + amgonnaUserId);
            // stringBuilder.append("&interestName="+);
            stringBuilder.append("&interestName=");
            ConnectionManager connectionManager = new ConnectionManager();
            String response = connectionManager.setUpHttpPost(TaskUrl,
                    stringBuilder.toString());

            if (response != null) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    errStatus = jsonObject.getInt("errStatus");
                    status = jsonObject.getString("status");

                } catch (Exception e) {
                    // TODO: handle exception
                }

            }

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (progressDialogStatus) {

                progressDialog.dismiss();

                if (errStatus == 0) {


// here i need to set the status message to button on adapter list item


                }

            }
        }

    }
4

1 回答 1

0

只需将要在按钮中显示的字符串保存在变量中即可。

例如:

 String temp=btnText;

然后再次调用您的列表适配器。并将您的 getView() 更改为

buttonAction.setText(temp);
于 2012-10-09T19:10:08.733 回答