Listview を使用して、Cursor からの 3 列の情報を画面上の 2 つの TextView に表示しています。左の TextView は静的ですが、右の TextView には、選択すると切り替わる 2 つの言語の翻訳があります。
私の問題は、ListView をスクロールするまでこれが正常に機能することです。その時点で、アダプターと ListView が同期していないように見え、動作が不安定になり、最終的に null ポインター例外が発生します。
onListItemClick コードは次のとおりです。
public void onListItemClick(ListView l, View v, int position, long id){
//first revert previous selection to English
if(previous_position!=99){
View vo =l.getChildAt(previous_position);
TextView pt = (TextView)vo.findViewById(R.id.english);
pt.setTextColor(Color.BLUE);
pt.setText(previous_text);
}
//now show current selection in Hindi
TextView t = (TextView) v.findViewById(R.id.translation);
t.setTextColor(Color.RED);
t.setText(gloCursor.getString(3));
//finally remember where we changed things so we can revert them
previous_position = position;
previous_text = gloCursor.getString(3);
// adapter data notification
//adapter.notifyDataSetChanged();
}
この場合は機能しなかったため、notifyDataStateChanged をコメントアウトしました。
これについての洞察や、より良いデザインをいただければ幸いです。
ありがとう、P.