Last active
October 30, 2016 10:13
-
-
Save kostovtd/0a8b978e24b0114a38f6e6dcbdafe2a8 to your computer and use it in GitHub Desktop.
Code Template - Activity & RecyclerViewAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
#parse("File Header.java") | |
public class ${NAME} extends AppCompatActivity { | |
private static final String TAG = ${NAME}.class.getSimpleName(); | |
/** | |
* Change the null parameter in {@code setContentView()} | |
* to a layout resource {@code R.layout.example} | |
*/ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
Log.d(TAG, "onCreate: hit"); | |
super.onCreate(savedInstanceState); | |
setContentView(null); | |
} | |
@Override | |
protected void onResume() { | |
Log.d(TAG, "onResume: hit"); | |
super.onResume(); | |
} | |
@Override | |
protected void onPause() { | |
Log.d(TAG, "onPause: hit"); | |
super.onPause(); | |
} | |
@Override | |
protected void onDestroy() { | |
Log.d(TAG, "onDestroy: hit"); | |
super.onDestroy(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import java.util.List; | |
#parse("File Header.java") | |
public class ${NAME} extends RecyclerView.Adapter<${NAME}.ViewHolder> { | |
private static final String TAG = ${NAME}.class.getSimpleName(); | |
private Context mContext; | |
private List<Object> mData; | |
/** | |
* Change {@link List} type according to your needs | |
*/ | |
public ${NAME}(Context context, List<Object> data) { | |
if(context == null) { | |
throw new NullPointerException("context can not be NULL"); | |
} | |
if(data == null) { | |
throw new NullPointerException("data list can not be NULL"); | |
} | |
this.mContext = context; | |
this.mData = data; | |
} | |
/** | |
* Change the null parameter to a layout resource {@code R.layout.example} | |
*/ | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()) | |
.inflate(null, parent, false); | |
return new ViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
// include binding logic here | |
} | |
@Override | |
public int getItemCount() { | |
return mData.size(); | |
} | |
public static class ViewHolder extends RecyclerView.ViewHolder { | |
// include {@link View} components here | |
public ViewHolder(View itemView) { | |
super(itemView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment