Skip to content

Instantly share code, notes, and snippets.

@zizibaloob
zizibaloob / MainActivity.java
Created March 1, 2018 18:14
Collapsing cardview example
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recycler = findViewById(R.id.recycler);
recycler.setAdapter(new MyAdapter());
}
@zizibaloob
zizibaloob / MyItemDecoration.java
Created December 12, 2017 18:16
Simple divider item decoration that also draws a divider on top of the first item
public class MyItemDecoration extends RecyclerView.ItemDecoration {
private static final int[] ATTRS = new int[]{ android.R.attr.listDivider };
private Drawable mDivider;
public MyItemDecoration(Context context) {
TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
@zizibaloob
zizibaloob / MainActivity.java
Created November 13, 2017 22:10
Tiny app to demonstrate nested RecyclerViews
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recycler = findViewById(R.id.list);
recycler.setLayoutManager(new LinearLayoutManager(this));
recycler.setAdapter(new CategoriesAdapter());
@zizibaloob
zizibaloob / MainActivity.java
Created October 31, 2017 22:03
Skeleton of an Android app to demonstrate a specific kind of activity transition
package com.example.transitionexample;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@zizibaloob
zizibaloob / MainActivity.java
Created September 12, 2017 22:14
Tiny app to demonstrate PagerAdapter
package com.example.stackoverflow;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@zizibaloob
zizibaloob / MainActivity.java
Created August 31, 2017 22:20
Tiny app to demonstrate one way of using FlexboxLayoutManager
package com.example.stackoverflow;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;