• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2018 The Android Open Source Project
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package androidx.viewpager2.widget.swipe;
18  
19  import android.view.LayoutInflater;
20  import android.view.ViewGroup;
21  import android.widget.TextView;
22  
23  import androidx.annotation.NonNull;
24  import androidx.recyclerview.widget.RecyclerView;
25  import androidx.recyclerview.widget.RecyclerView.ViewHolder;
26  import androidx.viewpager2.test.R;
27  
28  public class ViewAdapterActivity extends BaseActivity {
29      @Override
setAdapter()30      protected void setAdapter() {
31          mViewPager.setAdapter(new RecyclerView.Adapter<ViewHolder>() {
32              @NonNull
33              @Override
34              public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
35                      int viewType) {
36                  return new ViewHolder(
37                          LayoutInflater.from(ViewAdapterActivity.this).inflate(
38                                  R.layout.item_test_layout, parent, false)) {
39                  };
40              }
41  
42              @Override
43              public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
44                  TextView view = (TextView) holder.itemView;
45                  view.setText(String.valueOf(position));
46              }
47  
48              @Override
49              public int getItemCount() {
50                  return mTotalPages;
51              }
52          });
53      }
54  
55      @Override
validateState()56      public void validateState() {
57          // do nothing
58      }
59  
60      @Override
updatePage(int pageIx, int newValue)61      public void updatePage(int pageIx, int newValue) {
62          throw new IllegalStateException("not implemented");
63      }
64  }
65