-1
我在列表視圖中有一個EditText,我通過列表適配器填充,我的問題是,每當我在EditText中輸入任何文本並按回按鈕,所有更改都會丟失,但在另一個在其他位置(沒有列表視圖)的EditText一切正常(所有更改都保留),爲什麼發生這種情況,我該如何擺脫這個問題?Android:按下後退按鈕時出現Texttedit輸入丟失
的EditText代碼>>
<EditText
android:id="@+id/edit_card_list_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/editbox_cursor_margin"
android:layout_marginRight="@dimen/editbox_cursor_margin"
android:layout_marginTop="@dimen/edit_card_list_mid_gap"
android:background="@color/white"
android:ems="10"
android:enabled="true"
android:fontFamily="@string/roboto_light_font"
android:inputType="textNoSuggestions"
android:textSize="@dimen/forty_eight_font" >
</EditText>
Listadapter代碼>>
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
boolean convertViewWasNull = false;
if(rowView == null){
rowView = inflator.inflate(R.layout.edit_card_list_layout, parent, false);
convertViewWasNull = true;
}
TextView titleview = (TextView) rowView.findViewById(R.id.edit_card_list_title);
EditText detailview = (EditText) rowView.findViewById(R.id.edit_card_list_editText);
if(title.get(position) != null){
titleview.setText(title.get(position).toString());
}
if(detail.get(position) != null){
detailview.setText(detail.get(position).toString());
}else{
detailview.setText("");
}
detailview.requestFocus();
//InputMethodManager inputManager = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
//inputManager.restartInput(detailview);
if(convertViewWasNull){
detailview.addTextChangedListener(new GenericTextWatcher(detailview));
}
detailview.setTag(title.get(position).toString());
return rowView;
}
private class GenericTextWatcher implements TextWatcher{
private EditText view;
private GenericTextWatcher(EditText view) {
this.view = view;
}
public void afterTextChanged(Editable editable) {
text = editable.toString();
//save the value for the given tag :
EditCardListAdapter.this.editTextValues.put((String) view.getTag(),text);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
}