ExpandableListView
をNotfiyDataSetChanged
で更新しようと苦労しています。Android:SimpleExpandableListAdapterでNotifyDataSetChangedを正しく使用する方法
私は私のExpandableListView
に正しく表示されているWebサーバから一部のデータをダウンロードしています。
子アイテムをクリックすると、ユーザーは値を変更できるダイアログが表示されます。 この値はExpandableListView
に表示されるはずですので、クラス内の背景データを変更してNotifyDataSetChanged()
と呼び出してください。これは、Webサーバーに新しいリクエストを送信するまで、子アイテムに対しては正常に機能します。その後、私のダウンロード機能もローカル変更機能も、NotifyDataSetChanged()
は機能しません。
私が(ダイアログの後に)だけでなく、いくつかのグループ項目の内容を変更したいように、私は、あまりにも、私のグループのバックグラウンドデータを変更します。ただし、NotifyDataSetChanged()
は子アイテムに対して少なくとも2,3回は機能しますが、グループアイテムには何も影響しません。
私は私のバックグラウンドデータが実際に変更された場合、デバッガ& log.d()で確認しましたが、それはありません。
this questionとthis threadを見ると、notifyData
...間違っていると思います。しかし、私はそれが動作するはずの方法を把握することはできません。私が見つけた有用な機能はregisterDataSetObserver(observer)
でしたが、これをどのように使うべきかはわかりませんでした。 :/
ここは私のコードです。私は必要な部分にそれを取り除こうとしたので、いくつかの小さなエラーがあるかもしれません。
@SuppressWarnings("rawtypes")
private List children;
@SuppressWarnings("rawtypes")
private List groups;
private SimpleExpandableListAdapter expListAdapter;
/*download from webserver*/
void function1()
{
groups = new ArrayList();
children = new ArrayList();
*/go through a list I downloaded*/
for (...)
{
HashMap groupMap = new HashMap();
groupMap.put(groupName, downloadedList.getName());
groupMap.put(groupRate, downloadedList.getMatchrate() + getString(R.string.matchrate));
groups.add(groupMap);
ArrayList childList = new ArrayList();
HashMap childMap;
*/go through a sublist and fill child Map accordingly*/
for (...)
{
childMap = new HashMap();
childMap.put(...);
childList.add(childMap);
}
children.add(childList);
}
if (expListAdapter == null)
{
expListAdapter = new SimpleExpandableListAdapter(KnBDiagMan.this, groups,
R.layout.xlist_group_item,
new String[]
{ groupName, groupRate }, //private final static String components of my activity
new int[]
{ R.id.title, R.id.rate },
children,
R.layout.xlist_child_item,
new String[]
{ childName, childValue },
new int[]
{ R.id.child_title, R.id.child_value }
)
{
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
/*change of the text color of R.id.child_value's depending on content*/
}
};
setListAdapter(expListAdapter);
}
else
{
expListAdapter.notifyDataSetChanged();
}
}
/*change after Dialog*/
void function2()
{
String savedChildName = (String) ((HashMap) ((ArrayList) children.get(groupPos)).get(childPos)).get(childName);
for (int i = 0; i < children.size(); ++i)
{
List secondLevel = (ArrayList) children.get(i);
for (int j = 0; j < (secondLevel.size()); ++j)
{
HashMap map = (HashMap) secondLevel.get(j);
String compareName = (String) map.get(childName);
if (compareName.contentEquals(savedChildName))
{
HashMap newMap = new HashMap();
newMap.put(childName, savedChildName);
newMap.put(childValue, newValue);
secondLevel.set(j, newMap);
}
}
}
List newGroups = new ArrayList();
for(int i = 0; i < groups.size(); ++i)
{
String savedGroupName = (String) ((HashMap) groups.get(i)).get(groupName);
HashMap groupContent = new HashMap();
groupContent.put(groupName, savedGroupName);
groupContent.put(groupRate, getString(R.string.newString));
newGroups.add(groupContent);
}
groups = newGroups;
expListAdapter.notifyDataSetChanged();
}
アップデート:私はnotifyDataSetChanged
を呼び出すのではなく、新しいSimpleExpandableListAdapter
を作成する場合 すべてがintentedとして働いています。しかし、私はこれが解決策ではないと確信しています。アダプタを使用する際のポイントは何ですか?
作品なので、今までありがとうございました多く! :) – jellyfish