0

我正在使用EditText输入数据,但是当显示关闭和打开时,所有输入的数据都被清除,我使用的是 android 版本 2.2.2。

我的代码在这里:

  public void placeView() {    
        mEditText = new EditText(mContext);

        mTextView = new TextView(mContext);
        mEditText.setSingleLine();
        mEditText.onSaveInstanceState();
        mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        mTextView.setTextColor(mContext.getResources().getColor(R.color.white));
        mTextView.setTextColor(Color.WHITE);
        mtableRow = new LinearLayout(mContext);
        LinearLayout.LayoutParams trLayoutParams = new LinearLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.FILL_PARENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        mtableRow.setOrientation(LinearLayout.VERTICAL);

        mtableRow.setLayoutParams(trLayoutParams);
        LayoutParams tvLayoutParams = new LayoutParams(
                android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

        LayoutParams edtLayoutParams = new LayoutParams(
                android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

        mEditText.setLayoutParams(edtLayoutParams);
        mTextView.setLayoutParams(tvLayoutParams);

        mTextView.setTextSize(20);
        mtableRow.addView(mTextView);
        mtableRow.addView(mEditText);
        mtableRow.setPadding(10, 5, 10, 5);    
    }
4

1 回答 1

3

您可以尝试将文本从 EditText 保存到共享首选项

onPause()

然后从共享首选项中设置 EditText 文本

onResume()
于 2013-11-14T12:12:12.843 回答