ExpandableListView の getChildView 内に clickListener があります。ユーザーが子の 1 つをクリックすると、その行がリストから削除されます。この削除を反映するには、リスト ビューを更新する必要があります。私はデータ アダプターの内部にいるので、アダプターを設定したアクティビティの内部にいる場合のように、notifyDataSetChanged() を呼び出すことはできないと思います。
新しいアクティビティを開始できることはわかっていますが、これによりほぼ正確な複製がアクティビティ スタック (およびおそらくそれらの多く) に追加されます。startActivity を呼び出さずにこのリストを更新する方法を探しています。グループを手動で折りたたんで展開すると、リストが更新されるため、プログラムでこれを実行しようとしましたが、それも機能しません。(私が更新しているグループは常に位置 1 にあることに注意してください)。
新しいアクティビティを開始せずにこのリスト ビューを更新する方法を知っている人はいますか? ありがとう!
public class ExpandListAdapter extends BaseExpandableListAdapter {
public ExpandListAdapter(Context context, ArrayList<ExpandListGroup> groups, ExpandableListView expandableList) {
this.context = context;
this.groups = groups;
this.expandableList = expandableList;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, final ViewGroup parent) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//call method to remove this item from the database
//remove item from ArrayList
//refresh the view -- this is where I am stuck
//tried expandableList.collapseGroup(1); but null pointer resulted
}
}
}
}