本文整理汇总了Java中com.daimajia.swipedemo.adapter.RecyclerViewAdapter类的典型用法代码示例。如果您正苦于以下问题:Java RecyclerViewAdapter类的具体用法?Java RecyclerViewAdapter怎么用?Java RecyclerViewAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RecyclerViewAdapter类属于com.daimajia.swipedemo.adapter包,在下文中一共展示了RecyclerViewAdapter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.daimajia.swipedemo.adapter.RecyclerViewAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recyclerview);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle("RecyclerView");
}
}
// Layout Managers:
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Item Decorator:
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
recyclerView.setItemAnimator(new DefaultItemAnimator());
// Adapter:
String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
mAdapter = new RecyclerViewAdapter(this, recyclerView, mDataSet);
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
recyclerView.setAdapter(mAdapter);
try {
new ItemTouchBuilder()
.setList(mDataSet)
.setAdapter(mAdapter)
.setSwappable(false)
.create(recyclerView)
.attachToRecyclerView(recyclerView);
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: onCreate
import com.daimajia.swipedemo.adapter.RecyclerViewAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recyclerview);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle("RecyclerView");
}
}
// Layout Managers:
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Item Decorator:
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
recyclerView.setItemAnimator(new FadeInLeftAnimator());
// Adapter:
String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
mAdapter = new RecyclerViewAdapter(this, mDataSet);
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
recyclerView.setAdapter(mAdapter);
/* Listeners */
recyclerView.setOnScrollListener(onScrollListener);
}