Created
July 20, 2019 02:37
-
-
Save cutiko/943c60cd5170e79cbd9b3aa982316e32 to your computer and use it in GitHub Desktop.
Adapter template for Android Studio
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
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import androidx.recyclerview.widget.RecyclerView; | |
#set($model = $NAME.replace('sAdapter', '')) | |
#set($holder = $model+'Holder') | |
#set($item = $model.toLowerCase()) | |
#set($list = $item + 's') | |
public class ${NAME} extends RecyclerView.Adapter<${NAME}.${holder}> { | |
private final List<$model> $list = new ArrayList<>(); | |
@NonNull | |
@Override | |
public $holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_${item}, parent, false); | |
return new ${holder}(view); | |
} | |
@Override | |
public void onBindViewHolder(@NonNull $holder holder, int position) { | |
$model $item = ${list}.get(position); | |
} | |
@Override | |
public int getItemCount() { | |
return ${list}.size(); | |
} | |
class ${holder} extends RecyclerView.ViewHolder { | |
${holder}(@NonNull View itemView) { | |
super(itemView); | |
} | |
} | |
} |
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
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.recyclerview.widget.RecyclerView | |
#set($model = $NAME.replace('sAdapter', '')) | |
#set($holder = $model+'Holder') | |
#set($item = $model.toLowerCase()) | |
#set($list = $item + 's') | |
class ${NAME} : RecyclerView.Adapter<$holder>() { | |
private val $list = arrayListOf<$model>() | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): $holder { | |
val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item_$item, parent, false) | |
return $holder(view) | |
} | |
override fun onBindViewHolder(holder: $holder, position: Int) { | |
val $item = ${list}[position] | |
} | |
override fun getItemCount(): Int = ${list}.size | |
inner class ${holder}(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
init { | |
} | |
} | |
} |
@Allan-Nava these templates are supposed to be used as custom templates in Android Studio. Try to follow this instruction https://factory.dev/blog/templates-android-studio
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there anyway to import the template from github ?