11package com .daimajia .swipedemo ;
22
3+ import android .app .ActionBar ;
34import android .app .Activity ;
45import android .content .Context ;
56import android .content .Intent ;
67import android .graphics .drawable .Drawable ;
8+ import android .os .Build ;
79import android .os .Bundle ;
8- import android .support .v7 .widget .LinearLayoutManager ;
910import android .support .v7 .widget .RecyclerView ;
1011import android .util .Log ;
1112import android .view .Menu ;
1516import android .widget .Toast ;
1617
1718import com .daimajia .swipe .util .Attributes ;
18- import com .daimajia .swipedemo .adapter .RecyclerViewSimpleAdapter ;
19+ import com .daimajia .swipedemo .adapter .RecyclerViewAdvancedAdapter ;
1920
2021import org .lucasr .twowayview .ItemClickSupport ;
2122import org .lucasr .twowayview .TwoWayLayoutManager ;
2223import org .lucasr .twowayview .widget .DividerItemDecoration ;
2324import org .lucasr .twowayview .widget .ListLayoutManager ;
2425
26+ import java .util .ArrayList ;
27+ import java .util .Arrays ;
28+
2529public class RecyclerViewExample extends Activity {
2630
2731 private RecyclerView recyclerView ;
@@ -30,31 +34,36 @@ public class RecyclerViewExample extends Activity {
3034 // Our LayoutManager uses: https://github.com/lucasr/twoway-view to help with decoration and can be used for a more advanced config as well.
3135 // Read http://lucasr.org/2014/07/31/the-new-twowayview/ for a better understanding
3236 private RecyclerView .LayoutManager mLayoutManager ;
33- private Context mContext = this ;
3437
38+ private Context mContext = this ;
39+ private ArrayList <String > mDataSet ;
3540 @ Override
3641 protected void onCreate (Bundle savedInstanceState ) {
3742 super .onCreate (savedInstanceState );
3843 setContentView (R .layout .recyclerview );
3944 recyclerView = (RecyclerView ) findViewById (R .id .recycler_view );
45+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ) {
46+ ActionBar actionBar = getActionBar ();
47+ if (actionBar != null ) {
48+ actionBar .setTitle ("RecyclerView" );
49+ }
50+ }
4051
4152 /**
42- * The following comment is the sample usage of ArraySwipeAdapter .
53+ * Sample data .
4354 */
44- String [] adapterData = new String []{"Activity" , "Service" , "Content Provider" , "Intent" , "BroadcastReceiver" , "ADT" , "Sqlite3" , "HttpClient" ,
45- "DDMS" , "Android Studio" , "Fragment" , "Loader" , "Activity" , "Service" , "Content Provider" , "Intent" ,
46- "BroadcastReceiver" , "ADT" , "Sqlite3" , "HttpClient" , "Activity" , "Service" , "Content Provider" , "Intent" ,
47- "BroadcastReceiver" , "ADT" , "Sqlite3" , "HttpClient" };
55+ 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" };
4856
4957 // Uses a ListLayout manager from TwoWayView Lib:
5058 mLayoutManager = new ListLayoutManager (this , TwoWayLayoutManager .Orientation .VERTICAL );
5159 recyclerView .setLayoutManager (mLayoutManager );
5260 final Drawable divider = getResources ().getDrawable (R .drawable .divider );
5361 recyclerView .addItemDecoration (new DividerItemDecoration (divider ));
5462
55- mAdapter = new RecyclerViewSimpleAdapter (this , adapterData );
63+ mDataSet = new ArrayList <String >(Arrays .asList (adapterData ));
64+ mAdapter = new RecyclerViewAdvancedAdapter (this , mDataSet );
65+ ((RecyclerViewAdvancedAdapter ) mAdapter ).setMode (Attributes .Mode .Single );
5666 recyclerView .setAdapter (mAdapter );
57- ((RecyclerViewSimpleAdapter ) mAdapter ).setMode (Attributes .Mode .Single );
5867
5968 /* Listeners */
6069 ItemClickSupport itemClick = ItemClickSupport .addTo (recyclerView );
0 commit comments