本文整理匯總了Java中android.support.v7.widget.RecyclerView.AdapterDataObserver方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.AdapterDataObserver方法的具體用法?Java RecyclerView.AdapterDataObserver怎麽用?Java RecyclerView.AdapterDataObserver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.AdapterDataObserver方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: removeMultiple
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void removeMultiple() throws Exception {
mAdapter.add("A");
mAdapter.add("B");
mAdapter.add("C");
mAdapter.add("D");
assertThat(mAdapter.getItemCount()).isEqualTo(4);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.remove("D");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
verify(observer).onItemRangeRemoved(3, 1);
mAdapter.remove("C");
mAdapter.remove("B");
assertThat(mAdapter.getItemCount()).isEqualTo(1);
assertThat(mAdapter.getItem(0)).isEqualTo("A");
verify(observer).onItemRangeRemoved(2, 1);
verify(observer).onItemRangeRemoved(1, 1);
verifyNoMoreInteractions(observer);
}
示例2: sortSortedList
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void sortSortedList() throws Exception {
mAdapter.add("A");
mAdapter.add("B");
mAdapter.add("C");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.sort(new Comparator<String>() {
@Override
public int compare(final String o1, final String o2) {
return o1.compareTo(o2);
}
});
assertThat(mAdapter.getItem(0)).isEqualTo("A");
assertThat(mAdapter.getItem(1)).isEqualTo("B");
assertThat(mAdapter.getItem(2)).isEqualTo("C");
verifyZeroInteractions(observer);
}
示例3: replaceItemUiUnchanged
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void replaceItemUiUnchanged() throws Exception {
final UserAdapter adapter = new UserAdapter();
adapter.add(new User("A", "1"));
final User userB = new User("B", "2");
adapter.add(userB);
adapter.add(new User("C", "3"));
assertThat(adapter.getItemCount()).isEqualTo(3);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
adapter.registerAdapterDataObserver(observer);
final User newUserB = new User("B", "2");
adapter.replaceItem(userB, newUserB);
assertThat(adapter.getItemCount()).isEqualTo(3);
assertThat(adapter.getItem(1)).isEqualTo(newUserB);
verifyZeroInteractions(observer);
}
示例4: addAllMultiple
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void addAllMultiple() throws Exception {
mAdapter.add("A");
mAdapter.add("B");
assertThat(mAdapter.getItemCount()).isEqualTo(2);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
final ArrayList<String> list = new ArrayList<>();
list.add("C");
list.add("D");
mAdapter.addAll(list);
assertThat(mAdapter.getItemCount()).isEqualTo(4);
assertThat(mAdapter.getItem(2)).isEqualTo("C");
assertThat(mAdapter.getItem(3)).isEqualTo("D");
verify(observer).onItemRangeInserted(2, 2);
verifyNoMoreInteractions(observer);
}
示例5: replaceItemByUpdatingIt
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void replaceItemByUpdatingIt() throws Exception {
final UserAdapter adapter = new UserAdapter();
adapter.add(new User("A", "1"));
final User userB = new User("B", "2");
adapter.add(userB);
adapter.add(new User("C", "3"));
assertThat(adapter.getItemCount()).isEqualTo(3);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
adapter.registerAdapterDataObserver(observer);
final User newUser = new User("Z", "2");
adapter.replaceItem(userB, newUser);
assertThat(adapter.getItemCount()).isEqualTo(3);
assertThat(adapter.getItem(1)).isEqualTo(newUser);
verify(observer).onItemRangeChanged(1, 1, newUser);
verifyNoMoreInteractions(observer);
}
示例6: sort
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void sort() throws Exception {
mAdapter.add("C");
mAdapter.add("A");
mAdapter.add("B");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.sort(new Comparator<String>() {
@Override
public int compare(final String o1, final String o2) {
return o1.compareTo(o2);
}
});
assertThat(mAdapter.getItem(0)).isEqualTo("A");
assertThat(mAdapter.getItem(1)).isEqualTo("B");
assertThat(mAdapter.getItem(2)).isEqualTo("C");
verify(observer).onItemRangeMoved(0, 2, 1);
verifyNoMoreInteractions(observer);
}
示例7: registerAdapterDataObserver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
if (observer instanceof EasyRecyclerView.EasyDataObserver) {
mObserver = observer;
} else {
super.registerAdapterDataObserver(observer);
}
}
示例8: removeNonExisting
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void removeNonExisting() throws Exception {
mAdapter.add("A");
mAdapter.add("B");
mAdapter.add("C");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.remove("X");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
verifyZeroInteractions(observer);
}
示例9: addToEmpty
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void addToEmpty() throws Exception {
assertThat(mAdapter.getItemCount()).isEqualTo(0);
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.add("A");
assertThat(mAdapter.getItemCount()).isEqualTo(1);
assertThat(mAdapter.getItem(0)).isEqualTo("A");
verify(observer).onItemRangeInserted(0, 1);
verifyNoMoreInteractions(observer);
}
示例10: swap
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void swap() throws Exception {
mAdapter.add("A");
mAdapter.add("B");
mAdapter.add("C");
assertThat(mAdapter.getItemCount()).isEqualTo(3);
assertThat(mAdapter.getItem(0)).isEqualTo("A");
assertThat(mAdapter.getItem(1)).isEqualTo("B");
assertThat(mAdapter.getItem(2)).isEqualTo("C");
List<String> list = new ArrayList<>();
list.add("D");
list.add("E");
list.add("F");
list.add("G");
final RecyclerView.AdapterDataObserver observer =
mock(RecyclerView.AdapterDataObserver.class);
mAdapter.registerAdapterDataObserver(observer);
mAdapter.swap(list);
assertThat(mAdapter.getItemCount()).isEqualTo(4);
assertThat(mAdapter.getItem(0)).isEqualTo("D");
assertThat(mAdapter.getItem(1)).isEqualTo("E");
assertThat(mAdapter.getItem(2)).isEqualTo("F");
assertThat(mAdapter.getItem(3)).isEqualTo("G");
verify(observer).onItemRangeRemoved(0, 3);
verify(observer).onItemRangeInserted(0, 4);
verifyNoMoreInteractions(observer);
}
示例11: initViews
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initViews() {
View v = LayoutInflater.from(getContext()).inflate(
R.layout.briar_recycler_view, this, true);
recyclerView = (RecyclerView) v.findViewById(R.id.recyclerView);
emptyView = (TextView) v.findViewById(R.id.emptyView);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
showProgressBar();
// scroll down when opening keyboard
if (isScrollingToEnd) {
addLayoutChangeListener();
}
emptyObserver = new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
if (itemCount > 0) showData();
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
super.onItemRangeRemoved(positionStart, itemCount);
if (itemCount > 0) showData();
}
};
}
示例12: registerAdapterDataObserver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
if (adapter != null) {
adapter.registerAdapterDataObserver(observer);
}
}
示例13: unregisterAdapterDataObserver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
if (adapter != null) {
adapter.unregisterAdapterDataObserver(observer);
}
}
示例14: unregisterAdapterDataObserver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
super.unregisterAdapterDataObserver(observer);
mAdapter.unregisterAdapterDataObserver(observer);
}
示例15: registerAdapterDataObserver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
super.registerAdapterDataObserver(observer);
mAdapter.registerAdapterDataObserver(observer);
}