0

アクティビティがあり、テーマが dialog です。このアクティビティには、10 個の編集テキストがあります。1 つの編集ボックスで、編集ボックスにテキストを設定できません。

public void onCreate(Bundle savedInstanceState) {

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);     
    is_tablet=SharedVariables.sharedPrefDate.getBoolean("isTablet", false);
    if(!is_tablet){
        super.setTheme(android.R.style.Theme_Black_NoTitleBar);
    }
    //overridePendingTransition(R.anim.slide_bottom_to_top,0);
    super.onCreate(savedInstanceState);
    activity=UpdateCasePersonAddressScreen.this;
    setContentView(R.layout.update_person_address_screen);



    //allocating memory to objBLAddCasePersonScreenOperations
    objBLAddPersonAddressScreenOperations=new BLAddUpdatePersonAddressScreenOperations();
    objBLCommonOperations=new BLCommonOperations(); 
    getAllIds();


    //objPersonAddress=new clsPersonAddress();
    bundle = getIntent().getExtras();

    //code to get all objects using Bundle from previous activity
    if(bundle!=null){

        objPersonAddress = (clsPersonAddress) bundle.getParcelable("clsPersonAddress");
        System.out.println("from Extras");
        bundle=null;
    }        



    initTextFields();
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    /* if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }*/
}
public void initTextFields(){

    updatePersonAddressTitleEditText.setText(objPersonAddress.getAddressTitle());
    updatePersonAddressMemoEditText.setText(objPersonAddress.getAddressMemo());
    updatePersonAddressNameEditText.setText(objPersonAddress.getAddressName());
    updatePersonAddressBusinessNameEditText.setText(objPersonAddress.getAddressBusinessName());
    updatePersonAddressWorkPhoneEditText.setText(objPersonAddress.getAddressWorkPhone());
    updatePersonAddressHomePhoneEditText.setText(objPersonAddress.getAddressHomePhone());
    updatePersonAddressMobilePhoneEditText.setText(objPersonAddress.getAddressMobilePhone());
    updatePersonAddressAddressLine1EditText.setText(objPersonAddress.getAddressLine1());
    updatePersonAddressAddressLine2EditText.setText(objPersonAddress.getAddressLine2());
    updatePersonAddressCityEditText.setText(objPersonAddress.getAddressCity());

    System.out.println("objPersonAddress.getAddressState()))))))))))))))))))))))))))))))))))"+objPersonAddress.getAddressState());

    updatePersonAddressStateEditText.setText(objPersonAddress.getAddressState().toString());//setText(objPersonAddress.getAddressState(), TextView.BufferType.EDITABLE);
    System.out.println("updatePersonAddressStateEditText text is now is:"+updatePersonAddressStateEditText.getText().toString()+"null check:"+updatePersonAddressStateEditText.toString());
    System.out.println("below objPersonAddress.getAddressState()))))))))))))))))))))))))))))))))))"+objPersonAddress.getAddressState());

    updatePersonAddressZipEditText.setText(objPersonAddress.getAddressZip());
    updatePersonAddressCountryEditText.setText(objPersonAddress.getAddressCountry());
}

この問題で私を助けてくれる人はいますか。事前に助けてくれてありがとう。

4

3 に答える 3

4
EditText edit;// define it before onCreate

edit=(EditText)findViewById(R.id.edittext); //get it from xml

String value="123";
//simply use 

edit.setText(value);
于 2012-10-11T13:34:02.163 に答える
2

Android ネイティブ:

String text = "Example";
EditText edtText = (EditText) findViewById(R.id.edtText);
edtText.setText(text);`

見て!EditText は文字列値のみを受け入れ、必要に応じて文字列に変換します。

int、double、long 値の場合:

String.value(value);

例:

int i = 5;
edtText.setText(String.value(i));

Android の注釈:

@ViewById
EditText edtText;

設定するには:

@UiTread
void setText(){
    edtText.setText("Text");
}

呼び出すには:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    this.setText();
}
于 2012-10-11T13:09:13.040 に答える
1

このように書き留めるだけ

EditText editText=(EditText)findViewById(R.id.editText1);
        editText.setText("abc");
于 2012-10-11T12:55:23.427 に答える