0

我有一個滾動視圖,其表格佈局爲14行,每行有2個EditText字段。我有用戶點擊的按鈕,程序計算並打印答案。問題是,只要用戶單擊按鈕,然後在EditText中進行更改,然後再次單擊該按鈕,然後向上滾動輸入的字符中更改的EditText字段就會消失,但是當用戶單擊它時會消失。請幫我解決這個問題。這是xml文件。EditText文字滾動時消失

問題詳情: -
1.用戶在EditText字段中輸入文本。
2.用戶單擊按鈕。
3.用戶在一個或多個EditText字段中進行更改。
4.用戶單擊按鈕。
5.在上次更改的EditText字段中輸入的字符消失。

鏈接到完整的XML代碼: - http://pastebin.com/G01TcXN1

鏈接到完整的Java代碼: - http://pastebin.com/utRMQ60B

請幫我解決這個問題。

回答

1

我解決它,我剛剛從的RelativeLayout改變爲的LinearLayout這裏面解決了這個問題對我來說。

0

你可以按照下面的代碼可能對你有幫助。

if (convertView == null) { 

     holder = new ViewHolder(); 

     LayoutInflater vi = (LayoutInflater)  
     getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = vi.inflate(R.layout.element_in_game, null); 

     holder.scoreToUpdate = (EditText) convertView 
       .findViewById(R.id.elementUpdateScore); 

     convertView.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 

    } 
    initScoresToUpdateEditTexts(holder.scoreToUpdate, hint); 
    holder.scoreToUpdate.setText(scoresToUpdate[tmp_position]); 
    holder.scoreToUpdate.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, 
        int before, int count) { 
       scoresToUpdate[tmp_position] = s.toString(); 
      } 
     }); 

    return convertView; 
} 

或者你也可以參考這個LINK

+0

如果有更簡單的解決方案,我將不勝感激。順便說一下,這個人使用列表視圖,而我使用滾動視圖,所以如果你有任何替代解決方案,請讓我知道。 提前感謝你:) – Aadi