編集:
何かを編集しようとするとgetView()が呼び出されるため、DataAdapterからのデータが読み込まれ、編集した変更が表示されなくなることが原因であることがわかりました。
編集:
リストビューに行が少ない場合は問題ありませんが、リストビューが表示画面に表示できない行が多い場合(スクロールバーが他のレコードにスクロールするように見える)、問題が発生します。
ListViewを使用してインライン編集を実装したプロジェクトに取り組んでいます。つまり、データはリストビュー内で編集できます。
そのListViewの各アイテム/行にxmlを定義しました。カスタムDataAdapterを使用してデータをListViewにバインドしています。
そのアクティビティを初めてロードするときに、ListViewがロードされ、データを編集できます。これは正常に機能します。何かが編集されると、変更はSQLiteデータベースに保存されます。この目的のためのボタンがあります。
ここで問題となるのは、データが初めて保存され、リストビューが再度読み込まれた後、データを編集できなくなることです。データを編集しようとすると、キーボードが表示されてから自動的に消え、入力されたデータも消えます。スクリーンショットをご覧ください。
誰かがこの問題を解決するのを手伝ってもらえますか?
私のカスタムアダプタクラス:
public class QuestionAdapter extends ArrayAdapter<QuestionEntity> {
private ArrayList<QuestionEntity> items;
private Context CurrentContext;
private QuestionEntity CurrentItem;
private Cursor OptionsCursor;
public QuestionAdapter(Context context, ArrayList<QuestionEntity> items, Cursor curOptions)
{
super(context, R.layout.grid_item, items);
this.CurrentContext = context;
this.items = items;
this.OptionsCursor = curOptions;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//verify that the items list is still valid since
//the list may have been cleared during an update
if ((items == null) || ((position + 1) > items.size()))
return convertView; //Can't extract item
CurrentItem = items.get(position);
if(convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(CurrentContext);
convertView = inflater.inflate(R.layout.grid_item, null);
}
if (convertView != null)
{
TextView txtQuestion = (TextView) convertView.findViewById(R.id.txtQuestion);
txtQuestion.setText(CurrentItem.getTitle());
Spinner cmbOptions = (Spinner)convertView.findViewById(R.id.cmbOptions);
/*
* Load the options from OptionsCursor
*/
LoadOptions(cmbOptions);
/*
* Attach onItemClick event with cmbOptions
* When the user change the option we will populate the comments based on the option
*/
cmbOptions.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
try
{
//If MyCondition is true show msg to user.
}
catch(Exception ex)
{
ex.toString();
}
}
});
}
return convertView;
}
private void LoadOptions(Spinner iacOptions)
{
//Load data in the spinner using the OptionsCursor
}
}