0

onPostExecute()アプリケーションで Web サービスから値を取得しているときに呼び出すことができませんAndroid。以下のコードを追加しました。を返した後、スレッドは終了しますArrayList。私のコードに問題があるかどうかを確認できますか?

public class searchuser extends AsyncTask<Void, Void,ArrayList<DeleteuserDetails>>{

        protected ArrayList<DeleteuserDetails> doInBackground(Void... arg0) {
            // TODO Auto-generated method stub

            path.setNamespace();
            path.setMethod_name("searchuser");
            path.setSoap_action();
            path.setUrl();
            selecteduserType=String.valueOf(utype.getSelectedItem());
            userid=edtTxtUserId.getText().toString();
            if(!String.valueOf(utype.getSelectedItem()).equals("select")){

            Webservice service=new Webservice(path.getNamespace(), path.getMethod_name(), path.getUrl(), path.getSoap_action());
            try{
            SoapObject searchUser=service.getRequest();
             PropertyInfo search_userid=new PropertyInfo();
             search_userid.setName("userID");
             search_userid.setValue(userid);
             searchUser.addProperty(search_userid);
            /* PropertyInfo search_utype=new PropertyInfo(); 
             search_utype.setName("utype");
             search_utype.setValue(selecteduserType);
             searchUser.addProperty(search_utype);*/
             SoapSerializationEnvelope envelope = service.getEnvelope(searchUser);
                SoapObject response = service.getResponse(envelope);
                int count = response.getPropertyCount();
                for (int i = 0; i < count; i++) {

                    SoapObject result = (SoapObject) response.getProperty(i);
                    DeleteuserDetails deleteuserDetails=new DeleteuserDetails();
                    if(result.getPropertyAsString(4)!=null){
                    deleteuserDetails.setUserId(result.getPropertyAsString(4));
                    }
                    else{

                    }
                    if(result.getPropertyAsString(2)!=null){
                    deleteuserDetails.setUserName(result.getPropertyAsString(2));
                    }
                    else{

                    }
                    if(result.getPropertyAsString(3)!=null){
                        deleteuserDetails.setUserRole(result.getPropertyAsString(3));   
                    }
                    if(result.getPropertyAsString(1)!=null){
                        deleteuserDetails.setCreatedDate(result.getPropertyAsString(1));    
                    }
                    else{

                    }
                    try {
                        deleteuserDetails.setCreatedBy(result.getPropertyAsString(0).toString());
                    }
                    catch(NullPointerException npe) {
                        deleteuserDetails.setCreatedBy("null");
                    }
                    userdetail.add(deleteuserDetails);
                }

        }
            catch(Exception e){
                e.printStackTrace();
            }
            }
            else{
                alertbox.generateAlert(Deleteuser.this, "Please select usertype", "Default value Selected", R.drawable.noicon);

            }
            return userdetail;
        }
        protected void onPostExecute( ArrayList<DeleteuserDetails>deleteuserDetails) {
            deleteuserList = new TextView[deleteuserDetails.size()];

            for(int i=0;i<deleteuserDetails.size();i++){

                    TableRow deleteUserRow=new TableRow(Deleteuser.this);
                    deleteUserRow.setId(i);
                    deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                    selectcheck = new CheckBox(Deleteuser.this);
                    selectcheck.setId(i);
                    selectcheck.setTag(i);

                    deleteUserRow.addView(selectcheck);

                    deleteuserList[i]=new TextView(Deleteuser.this);
                //  deleteuserList[i].setId(i);
                    deleteuserList[i].setTag(i);
                    deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
                    deleteUserRow.addView(deleteuserList[i]);

                    uName=new TextView(Deleteuser.this);
                    uName.setId(i);
                    uName.setText(deleteuserDetails.get(i).getUserName());
                    deleteUserRow.addView(uName);

                    Userrole=new TextView(Deleteuser.this);
                    Userrole.setId(i);
                    Userrole.setPadding(20, 0, 0, 0);
                    Userrole.setText(deleteuserDetails.get(i).getUserRole());
                    deleteUserRow.addView(Userrole);

                    CreatedDate=new TextView(Deleteuser.this);
                    CreatedDate.setId(i);
                    CreatedDate.setPadding(20, 0, 0, 0);
                    CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
                    deleteUserRow.addView(CreatedDate);

                    CreatedBy=new TextView(Deleteuser.this);
                    CreatedBy.setId(i);
                    CreatedBy.setPadding(20, 0, 0, 0);
                    CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
                    deleteUserRow.addView(CreatedBy);
                    userdetailTable.addView(deleteUserRow,
                            new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                    LayoutParams.WRAP_CONTENT));



                    selectcheck.setOnClickListener(listener);
                    Log.i("Exception",""+i);
                }
            TableRow addcomponentrow=new TableRow(Deleteuser.this);
            addcomponentrow.setId(200);
            addcomponentrow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

            Button Deletecomponentbtn=new Button(Deleteuser.this);
            Deletecomponentbtn.setText("Delete");
            Deletecomponentbtn.setId(200);
            Deletecomponentbtn.setPadding(10, 0, 20, 2);
            Deletecomponentbtn.setBackgroundColor(color.red);
            addcomponentrow.addView(Deletecomponentbtn);

            userdetailTable.addView(addcomponentrow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
            Deletecomponentbtn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    // TODO Auto-generated method stub
                    new DeleteUserid().execute(checkedValue);
                }
            });


        }
        final OnClickListener listener=new OnClickListener() {

            @Override
            public void onClick(View v) {

                // TODO Auto-generated method stub
                int index = (Integer) v.getTag();
                checkedValue=(String) deleteuserList[index].getText();

            }
        };

    }
4

2 に答える 2

2

変化する

protected void onPostExecute( ArrayList<DeleteuserDetails>deleteuserDetails) {
                                                     // ^^^

@Override
protected void onPostExecute( ArrayList<DeleteuserDetails> deleteuserDetails) {
 // your code here...
于 2012-12-26T08:23:01.267 に答える
0

DeleteuserDetailsこれを次のように初期化します。

  DeleteuserDetails deleteuserDetails = new DeleteuserDetails();

文字列変数を宣言して代入する

  String userId = "";
  String userName = "";
  String userRole = "";
  String createdDate = "";
  String createdBy = "";

モデルで、次のようにコンストラクターを生成します。

  DeleteuserDetails(String userId, String userName, String userRole, String createdDate, String createdBy) {
   this.userId = userId;
   this.userName = userName;
   this.userRole = userRole;
   this.createdDate = createdDate;
   this.createdBy = createdBy;
 }

で、次の操作を行います。doInBackground(..)

   if (result.getPropertyAsString(4) != null) 
             userId = result.getPropertyAsString(4);
   if (result.getPropertyAsString(2) != null) 
             userName = result.getPropertyAsString(2);
   if (result.getPropertyAsString(3) != null) 
             userRole = result.getPropertyAsString(3);
   if (result.getPropertyAsString(1) != null) 
             createdDate = result.getPropertyAsString(1);
    if (result.getPropertyAsString(0) != null) 
        createdBy = result.getPropertyAsString(0);

   deleteuserDetails = new  DeleteuserDetails(userId, userName, userRole, createdDate,  createdBy);

     userdetail.add(deleteuserDetails);

onPostExecute() メソッドにメソッドを追加runOnUiThread()し、次の手順に従います。

        runOnUiThread(new Runnable() {

            @Override
            public void run() {


            deleteuserList = new TextView[deleteuserDetails.size()];

            for(int i=0;i<deleteuserDetails.size();i++){

                    TableRow deleteUserRow=new TableRow(Deleteuser.this);
                    deleteUserRow.setId(i);
                    deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                    selectcheck = new CheckBox(Deleteuser.this);
                    selectcheck.setId(i);
                    selectcheck.setTag(i);

                    deleteUserRow.addView(selectcheck);

                    deleteuserList[i]=new TextView(Deleteuser.this);
                //  deleteuserList[i].setId(i);
                    deleteuserList[i].setTag(i);
                    deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
                    deleteUserRow.addView(deleteuserList[i]);

                    uName=new TextView(Deleteuser.this);
                    uName.setId(i);
                    uName.setText(deleteuserDetails.get(i).getUserName());
                    deleteUserRow.addView(uName);

                    Userrole=new TextView(Deleteuser.this);
                    Userrole.setId(i);
                    Userrole.setPadding(20, 0, 0, 0);
                    Userrole.setText(deleteuserDetails.get(i).getUserRole());
                    deleteUserRow.addView(Userrole);

                    CreatedDate=new TextView(Deleteuser.this);
                    CreatedDate.setId(i);
                    CreatedDate.setPadding(20, 0, 0, 0);
                    CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
                    deleteUserRow.addView(CreatedDate);

                    CreatedBy=new TextView(Deleteuser.this);
                    CreatedBy.setId(i);
                    CreatedBy.setPadding(20, 0, 0, 0);
                    CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
                    deleteUserRow.addView(CreatedBy);
                    userdetailTable.addView(deleteUserRow,
                            new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                    LayoutParams.WRAP_CONTENT));



                    selectcheck.setOnClickListener(listener);
                    Log.i("Exception",""+i);
                }
            TableRow addcomponentrow=new TableRow(Deleteuser.this);
            addcomponentrow.setId(200);
            addcomponentrow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

            Button Deletecomponentbtn=new Button(Deleteuser.this);
            Deletecomponentbtn.setText("Delete");
            Deletecomponentbtn.setId(200);
            Deletecomponentbtn.setPadding(10, 0, 20, 2);
            Deletecomponentbtn.setBackgroundColor(color.red);
            addcomponentrow.addView(Deletecomponentbtn);

            userdetailTable.addView(addcomponentrow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
            Deletecomponentbtn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    // TODO Auto-generated method stub
                    new DeleteUserid().execute(checkedValue);
                }
            });


        }
        final OnClickListener listener=new OnClickListener() {

            @Override
            public void onClick(View v) {

                // TODO Auto-generated method stub
                int index = (Integer) v.getTag();
                checkedValue=(String) deleteuserList[index].getText();

            }
        };

            }
        });
    }
于 2012-12-26T08:23:01.473 に答える