매우 구체적인 질문이 있습니다. 모든 @Bindable 필드 나 또한 게터를 사용확장형 목록보기의 Android 데이터 바인딩
Class ParticipantList
public ObservableArrayList<Participant> list = new ObservableArrayList<>();
//some Methods to add items and concstructor
와 세터 :
Class Participant
Public String Name;
//and so on
Public ObservableArrayList<Drink> DrinkList;
End Class
Class Drink extends BaseObservable
@Bindable
Public String Name;
@Bindable
Public Float Price;
End Class
의 ViewModel : 나는이 같은 데이터 모델을 https://developer.android.com/topic/libraries/data-binding/index.html
: 나는 안드로이드 데이터 바인딩 라이브러리를 사용하고 있습니다. 이제
나는 XML을 통해 expandablelistview에 어댑터를 결합 expandablelistview로 활동하고 사용자 정의 @BindingAdapter이 같은있다 :이 정적 메소드 바인딩 도우미 클래스에서
//in XML for the layout
<layout xmlns:bind="http://schemas.android.com/apk/res-auto"
<data>
<variable name="Participants" type="com.example.ParticipantList"/>
</data>
<ExpandableListview>
<bind:participants=Particpants.list>
을
@BindingAdapter("participants")
public static void bindList(ExpandableListView view, ObservableArrayList<Participant> list) {
ParticipantListAdapter adapter = new ParticipantListAdapter(list);
view.setAdapter(adapter);
}
그리고 마지막으로 내 어댑터 :
Class ParticpantListAdapter Extends ExpandableListAdapter {
public ObservableArrayList<Participant> list;
@Override
public View getGroupView(..)
ParticipantListItemBinding binding = DataBindingUtil.inflate(inflater,R.layout.participant_list_item, parent, false);
binding.setParticipant(list.get(groupposition));
return binding.getRoot();
}
@Override
public View getChildView(..) {
DrinkListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.drink_list_item, parent, false);
binding.setDrink(list.get(goupposition).DrinkList.get(childposition));
return binding.getRoot();
}
나는 2 이상의 XML을 LayoutFiles는 참가자와 음료 클래스에 바인딩 된 layout.drink_list_item + layout.participant_list_item을 데이터 바인딩으로 사용합니다.
여기서는별로 중요하지 않은 코드를 건너 뜁니다. 레이아웃 (layout.participant_list_item)에 버튼이있어서 모든 데이터 링크의 음료수 목록에 새 음료수를 추가 할 수있는 새로운 활동이 열립니다. 활동을 마칠 때 새로운 어린이가 그룹에 추가되어야합니다. 그러나 그것은 내가 붕괴하고 그룹을 한 번 확장 한 후에 나타납니다. 일반적으로 데이터 바인딩은 @ Bindable 필드에 대해 NotifyPropertychanged를 호출하거나 직접 연결된 ObservableArrayList에 새 항목을 추가 할 때이 작업을 수행합니다. 그러나 이것은 사실이 아닙니다. ObservableArrayList에있는 항목의 ObservableArrayList에 항목을 추가합니다. 해당 그룹의 하위 그룹 만 새로 고치는 방법이 있습니까? 아니면 내 접근 방식이 어딘지 잘못 됐니?
필자는 특정 조건이 충족되면 ExpandableListView 활동의 전체 다시 그리기로 연결되는 모든 바인딩을 새로 고쳐야한다는 onResume 이벤트에서 내 기본 바인딩 활동을 말합니다. 항목이 다시 축소됩니다 (원하는 동작이 아님).
나는 지금 내 개발 장소가 아니기 때문에 내 기억에서 모든 코드를 썼다. 그러나이 문제는 며칠 동안 저를 괴롭 힙니다. 지금까지 Databinding 및 ExpandableListView의보기 흉한 예제를 찾을 수 없었습니다. 더 많은 정보가 필요하면 그냥 물어보십시오.
좋은 해결책을 찾는데 도움이되는 힌트가있어서 기쁩니다.
내 첫 번째 질문입니다. 게시물이 모든 요구 사항을 충족시키지 못하는 경우 친절하시기 바랍니다.
고맙습니다.
// 편집. 일부 코드 수정. 도움이되는 의견이있는 사람이 있습니까?
을 나는이 정확한 문제로 실행하고, 당신이 그것을 알아낼 수 있었습니까? –
슬프게도 취미 프로젝트 였기 때문에 거기에 갇혀 깨끗한 해결책을 찾지 못했습니다. 그래서 새로 고침 한 모든 바인딩 메소드를 사용했는데, 이는 못 생겼지 만 적어도 그렇게 작동했습니다. 적절한 해결책을 찾으면 알려주세요. – Mono