Created
April 10, 2017 03:47
-
-
Save fnovoac/f973b37bce07b9aadf980ab52c01d11b to your computer and use it in GitHub Desktop.
Algunas Plantillas para 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
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.util.List; | |
/* Referencia: | |
https://github.com/vectorhead2015/android-custom-arrayadapter-recyclerview/blob/master/app/src/main/java/demo/example/com/customarrayadapter/adapter/AndroidFlavorAdapter.java | |
*/ | |
public class ${NAME}Adapter extends ArrayAdapter<${NAME}> { | |
private Context mContext; | |
private List<${NAME}> m${NAME}s; | |
/** | |
* This is our own custom constructor (it doesn't mirror a superclass constructor). | |
* The context is used to inflate the layout file, and the List is the data we want | |
* to populate into the lists | |
* | |
* @param context The current context. Used to inflate the layout file. | |
* @param androidFlavors A List of AndroidFlavor objects to display in a list | |
*/ | |
public ${NAME}Adapter(Context context, List<${NAME}> items) { | |
// Here, we initialize the ArrayAdapter's internal storage for the context and the list. | |
// the second argument is used when the ArrayAdapter is populating a single TextView. | |
// Because this is a custom adapter, it is not going to use this second argument, | |
// so it can be any value. Here, we used 0. | |
super(context, 0, items); | |
mContext = context; | |
m${NAME}s = items; | |
} | |
// Actualizar según los items de layout de cada elemento de ListView | |
private static class ViewHolder { | |
protected ImageView imgMovie; | |
protected TextView tvName; | |
protected TextView tvGenre; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
ViewHolder viewHolder; | |
if (convertView == null) { | |
// Inflate the layout (reemplazar "mLayoutId" con el layout respectivo) | |
convertView = LayoutInflater.from(mContext).inflate(mLayoutId, parent, false); | |
// create the view holder | |
viewHolder = new ViewHolder(); | |
//------- reemplazar según nuestro xml que representa una fila del ListView | |
viewHolder.imgMovie = (ImageView) convertView.findViewById(R.id.imgMovie); | |
viewHolder.tvName = (TextView) convertView.findViewById(R.id.tvName); | |
viewHolder.tvGenre = (TextView) convertView.findViewById(R.id.tvGenre); | |
convertView.setTag(viewHolder); | |
} else { | |
viewHolder = (ViewHolder) convertView.getTag(); | |
} | |
// Set the movie data | |
${NAME} item = m${NAME}s.get(position); | |
if (item != null) { | |
if (viewHolder.imgMovie != null) { | |
viewHolder.imgMovie.setImageResource(item.getImageId()); | |
} | |
if (viewHolder.tvName != null) { | |
viewHolder.tvName.setText(item.getName()); | |
} | |
if (viewHolder.tvGenre != null) { | |
viewHolder.tvGenre.setText(item.getGenre()); | |
} | |
} | |
return convertView; | |
} | |
} |
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
public class GreenDaoManager { | |
private static GreenDaoManager mInstance; | |
private DaoMaster mDaoMaster; | |
private DaoSession mDaoSession; | |
public static GreenDaoManager getInstance() { | |
if (mInstance == null) { | |
mInstance = new GreenDaoManager(); | |
} | |
return mInstance; | |
} | |
public GreenDaoManager() { | |
// Debemos crear una clase que implemente Application llamada MyApp | |
DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(MyApp.getContext(), "${PROJECT_NAME}-db", null); | |
mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase()); | |
mDaoSession = mDaoMaster.newSession(); | |
} | |
public DaoMaster getMaster() { | |
return mDaoMaster; | |
} | |
public DaoSession getSession() { | |
return mDaoSession; | |
} | |
public DaoSession getNewSession() { | |
mDaoSession = mDaoMaster.newSession(); | |
return mDaoSession; | |
} | |
/* Actualizar esta parte según los DAO que tengamos | |
public CustomerDao getCustomerDao(){ | |
return mDaoSession.getCustomerDao(); | |
} | |
public OrderDao getOrderDao(){ | |
return mDaoSession.getOrderDao(); | |
} | |
*/ | |
} |
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
public class ${NAME} extends Application { | |
private static Context mContext; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
mContext = getApplicationContext(); | |
GreenDaoManager.getInstance(); | |
} | |
public static Context getContext() { | |
return mContext; | |
} | |
public static void setContext(Context mContext) { | |
${NAME}.mContext = mContext; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment