私のプロジェクトでは、基本的に EditText に含まれる ListView をユーザーに表示する必要があります。
アンケートのようなもので、質問に答えると、下に降りて次の質問に答えることができます。(そして戻る)
public class onAdapter extends BaseAdapter {
List<PointVerification> mObjects;
Context mContext;
LayoutInflater mInflater;
HashMap<Integer, List<ChoixPointVerification>> mChoix;
HashMap<Integer, ReponsePointVerification> mReponses;
HashMap<Integer, String> mReponsesActuel;
Integer mPositionSelectionne;
Integer mIdIntervention;
/**
* Constructeur
* @param context
* @param listePointsVerification Liste des points de vérification à afficher.
* @param listeChoixPointsVerification liste des choix de points de vérification pour chaque point de vérification.
* @param listeReponsesPointsVerification réponses déjà fournies pour chaque point de vérification
* @param idIntervention Identifiant de l'intervention
*/
public onAdapter(
Context context,
Integer idIntervention,
List<PointVerification> listePointsVerification,
List<ChoixPointVerification>> listeChoixPointsVerification,
ReponsePointVerification> listeReponsesPointsVerification) {
this.mInflater = LayoutInflater.from(context);
this.mContext = context;
this.mObjects = listePointsVerification;
this.mChoix = listeChoixPointsVerification;
this.mReponses = listeReponsesPointsVerification;
this.mIdIntervention = idIntervention;
// préparation des réponses par position
this.mReponsesActuel = new HashMap<Integer, String>();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
final Integer idPointVerification = getItem(position).id;
if (convertView == null)
{
row = mInflater.inflate(R.layout.intervention_reponses_controle_nombre, null);
EditText edValeur = (EditText) row.findViewById(R.id.edValeur);
// Ajout de l'évènement lorsque l'on change la valeur
// evènement d'enregistrement
edValeur.addTextChangedListener(new TextWatcher()
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
// This hashmap is a try workaround to the bug
// i register all modifications into this hashmap
mReponsesActuel.put(
idPointVerification,
s.toString());
// SAVE PROCEDURE
// REMOVED FOR THE EXAMPLE
// BUT I UPDATE MY DATABASE
}
});
}
else
{
row = convertView;
}
EditText edValeur = (EditText) row.findViewById(R.id.edValeur);
// update of the text
// it is the contained in the hashmap
if (mReponsesActuel.containsKey(idPointVerification)) {
String valeur = mReponsesActuel.get(idPointVerification);
edValeur.setText(valeur);
// otherwhise i will look into the database
} else if (mReponses != null && mReponses.containsKey(idPointVerification)
&& mReponses.get(idPointVerification).valeur != null) {
edValeur.setText(mReponses.get(idPointVerification).valeur);
}
else
{
edValeur.setText("");
}
return row;
}
}
理由はわかりませんが、ユーザーが ListView でダウンすると、コンテンツは保存されず、他の EditText などの特別な値が表示されます。その動作を修正する方法が見つかりませんでした。本当に急いでいます。
基本的に、データをデータベースに登録する TextWatcher と、すべての値を含む一時的な HashMap を作成しました。そのデータは、GetView が呼び出されるとコールバックされます。その初期化を削除すると、EditText が消去されます。
注:コードでいくつかのテストを行ったので、別の問題があるかもしれません。
編集
問題のあるプロジェクトをアップロードしました: http://dl.free.fr/rbqOhUfJF
問題を再現する手順は次のとおりです。
プロジェクトをデバッグモードで起動する
最初の行 A に、2 番目の B に、3 番目の C に書きます
C が非表示になるまで下にスクロールします
一番上までスクロールします。結果 : これ以上テキストはありません。
デバッグ ログをよく見ると、afterText の行が表示されます。パート 2 でテキストを記述するたびに、イベントの登録を含むデバッグ行が表示されます。
しかし、フェーズ 3 では、アイテムを非表示にします。イベントは「」で開始されます
結果: 4 番目のフェーズで、"" 文字列をロードします。