Android 如何更改片段中FormEditText或EditText的值?

Android 如何更改片段中FormEditText或EditText的值?,android,android-fragments,android-volley,Android,Android Fragments,Android Volley,我试着在onCreate、onStart甚至在onAttach()中实现它,但是值没有改变。这些值与第一次创建片段时的值相同。我是这样做的 import org.json.JSONObject; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInfla

我试着在onCreate、onStart甚至在onAttach()中实现它,但是值没有改变。这些值与第一次创建片段时的值相同。我是这样做的

import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.andreabaccega.widget.FormEditText;
import com.thesis.rentalpropertymanagement.R;
import com.thesis.rentalpropertymanagement.framework.RPMApiRequests;
import com.thesis.rentalpropertymanagement.framework.VolleyController;
import com.thesis.rentalpropertymanagement.interfaces.OnApiSuccessCalback;
import com.thesis.rentalpropertymanagement.models.RentalProperty;

public class ProfileFragment
    extends Fragment
    implements OnApiSuccessCalback {

    public static String ARGS_PROFILE = "profile";

    private RentalProperty property;

    private Button updateBtn;

    private FormEditText nameTxt;
    private FormEditText contactNoTxt;
    private FormEditText emailTxt;
    private FormEditText usernameTxt;
    private FormEditText passwordTxt;
    private FormEditText priceConditionsTxt;
    private FormEditText bathsTxt;
    private FormEditText bedroomsTxt;
    private FormEditText totalRoomsTxt;
    private FormEditText fullyFurnishedTxt;
    private FormEditText yearBuiltTxt;

    private View fragment;

    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        fragment = inflater.inflate(R.layout.fragment_property_profile,
            container, false);
        property = new RentalProperty((String) getArguments().get(ARGS_PROFILE));
        setUpViews(fragment);
        Log.d("ERNEST", "ProfileFragment : " + property.getJsonData().toString());
        return fragment;
    }

    public void setUpViews(View fragment) {
        updateBtn = (Button) fragment.findViewById(R.id.updateBtn);
        updateBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dataAreValid()) {
                      VolleyController.instance.addToRequestQueue(RPMApiRequests
                        .updatePropertyInfo(getActivity(),
                            ProfileFragment.this, 1,
                            VolleyController.instance.getIpAddress(),
                            property));
                }

            }
        });
        nameTxt = (FormEditText) fragment.findViewById(R.id.name);
        nameTxt.setText(property.getLandlordName());

        contactNoTxt = (FormEditText) fragment.findViewById(R.id.contact_no);
        contactNoTxt.setText(property.getContactNo());

        emailTxt = (FormEditText) fragment.findViewById(R.id.email_ad);
        emailTxt.setText(property.getEmail());

        usernameTxt = (FormEditText) fragment.findViewById(R.id.username);
        usernameTxt.setText(property.getUsername());

        passwordTxt = (FormEditText) fragment.findViewById(R.id.password);
        passwordTxt.setText(property.getPassword());

        priceConditionsTxt = (FormEditText) fragment
            .findViewById(R.id.price_conditions);
        priceConditionsTxt.setText(property.getPriceConditions());

        bathsTxt = (FormEditText) fragment.findViewById(R.id.baths);
        bathsTxt.setText(String.valueOf(property.getBaths()));

        bedroomsTxt = (FormEditText) fragment.findViewById(R.id.bedrooms);
        bedroomsTxt.setText(String.valueOf(property.getBedrooms()));

        totalRoomsTxt = (FormEditText) fragment.findViewById(R.id.total_rooms);
        totalRoomsTxt.setText(String.valueOf(property.getTotalRooms()));

        fullyFurnishedTxt = (FormEditText) fragment
            .findViewById(R.id.fully_furnished);
        fullyFurnishedTxt.setText(getFullyFurnished());

        yearBuiltTxt = (FormEditText) fragment.findViewById(R.id.year_built);
        yearBuiltTxt.setText(property.getYearBuilt());
    }

    private String getFullyFurnished() {
        int fullyFurnished = property.isFullyFurnished();
        if (fullyFurnished == 1) {
            return "Y";
        } else {
            return "N";
        }
    }

    private int isFullyFurnished() {
        String fullyFurnished = fullyFurnishedTxt.getText().toString();
        if (fullyFurnished.toUpperCase().contains("Y")) {
            return 1;
        } else {
            return 0;
        }
    }

    public boolean dataAreValid() {
        if (nameTxt.testValidity() && contactNoTxt.testValidity()
            && emailTxt.testValidity() && usernameTxt.testValidity()
            && passwordTxt.testValidity()
            && priceConditionsTxt.testValidity() && bathsTxt.testValidity()
            && bedroomsTxt.testValidity() && totalRoomsTxt.testValidity()
            && fullyFurnishedTxt.testValidity()
            && yearBuiltTxt.testValidity()) {
            property = new RentalProperty(nameTxt.getText().toString(),
                contactNoTxt.getText().toString(), emailTxt.getText()
                .toString(), usernameTxt.getText().toString(),
                passwordTxt.getText().toString(), priceConditionsTxt
                .getText().toString(), Integer.parseInt(bathsTxt
                .getText().toString()),
                Integer.parseInt(bedroomsTxt.getText().toString()),
                Integer.parseInt(totalRoomsTxt.getText().toString()),
                isFullyFurnished(), yearBuiltTxt.getText().toString());
            return true;
        }
        return false;
    }

    @Override
    public void OnApiSuccess(JSONObject response, int requestCode) {
        // TODO Auto-generated method stub
    }
}

我在onActivityCreated中设置了Textview的值

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);


        inputSend = (TextView) getActivity().findViewById(R.id.inputSend);
        inputSend.setText("xxxxxxx");

}

onCreateView()
中执行此操作,这取决于您尝试执行的操作。我一直在执行此操作。它似乎没有改变值。setUpViews方法通过
findViewById
片段中获取视图,然后使用
setText
从我的模型中设置数据……您可以发布
片段的相关代码段吗?我将发布它。我只想诅咒这个片段,即使我卸载了应用程序,它仍然保持不变!就像编程中的WTfluckly一样,事情的发生是有原因的,因此,如果您共享一些可能导致问题的源代码,我们会找到答案:)