カスタムアダプタを使用してListViewをソートするボタンがあります。次のようにボタンのリスナーがある:ListView not OnClickListenerから再ペイント
collectionSort.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sortOrder = -sortOrder;
Log.d("DBGINF", "Sort Order: " + sortOrder);
m.sortByTitles(sortOrder);
m.notifyDataSetChanged();
});
ソート順の変更それが必要、と配列内のデータをソートするなど、実際のビューはいえnotifyDataSetChangedによって更新されることはありません。
public void sortByTitles(int dir) {
if (dir > 0) {
sort(new StringComparator());
} else if (dir < 0) {
sort(new ReverseStringComparator());
}
Log.d("Data Set: ", this.getItem(0) + "");
}
notifyDataSetChanged()
が今までOnClickListener
内部のビューを更新しますが、常に適切OnClickListenersの 1外に動作しません。ここでsortByTitles()メソッドです。私は間違って何をしていますか?ここで
EDIT
は、アダプタクラスのコンストラクタです:
CollectionObject[] sample = new CollectionObject[] { c1, c2, c3, c4, c5, c6 };
final MainMenuArrayAdapter m = new MainMenuArrayAdapter(this, sample);
:
public MainMenuArrayAdapter(Context context, CollectionObject[] objects) {
super(context, R.layout.mainmenurow, objects);
myContext = context;
}
そして、ここでは、それが活動ののonCreate()メソッドで初期化される方法ですここで、c1〜c6はテストのための一時的なCollectionObjectです。
'myCollections'は何ですか?あなたのアダプタのより多くのコードを見る必要があります。 – st0le
アダプタをどのように初期化したかを確認する必要がありますか? – st0le
私は自分の質問をカスタムアダプターのコンストラクターで編集しました。 myCollectionsはCollectionObjectsをすべて保持する配列です – jpalm