He estado tomando un par de cursos online sobre Desarrollo de Aplicaciones Android, para ayudarme en un proyecto que tengo en mente, usando un Custom Drawer para navegar entre secciones (Fragments) y usando Parse.com como backend para la obtencion de la data. Les dejo un mini-tutorial.
main_fragment.xml
Este es el fragmento que se necesita mostrar. Tiene un TextView en la parte superior para usar como titulo
This is the fragment you need to show on the app. Notice the ListView has an ID. It also has a TextView to show headlines
adapter_layout.xml
Este es el diseno que nuestro ‘Custom Adapter’ usara para insertar la data a cada Fila de nuestro ‘ListView’
This is the layout our custom adapter is going to use to fetch the data into each Row in our ListView. The style here is going to show as each item for the main List
CustomAdapter.java
Este es nuestro adaptor. Usa el objeto placesObject para colocar el texto en los campos de adapter_layout.xml
This is our custom adapter that uses a ParseObjectplacesObject
to set the text of ouradapter_layout.xml
fields/** * Custom Adapter for Places List * Created by Leonel on 01-01-2015. */ public class PlacesAdapter extends ArrayAdapter { protected Context mContext; protected ListmPlaces; public PlacesAdapter(Context context, List place) { super(context, R.layout.places_custom_fragment, place); mContext = context; mPlaces = place; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate( R.layout.places_custom_fragment, null); holder = new ViewHolder(); holder.placeName = (TextView) convertView .findViewById(R.id.txtPlace); holder.placeDescription = (TextView) convertView .findViewById(R.id.txtPlaceDescription); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ParseObject placesObject = mPlaces.get(position); // title String place = placesObject.getString("placeName"); holder.placeName.setText(place); // content String description = placesObject.getString("placeDescription"); holder.placeDescription.setText(description); return convertView; } public static class ViewHolder { TextView placeName; TextView placeDescription; } }
MainFragment.java
Creamos la consulta a Parse.com y lo enviamos a nuestro adaptor para ser expandido
In ouronActivityCreated
, we make our Parse.com query and send it to our adapter to be expanded.public class PlacesFragment extends Fragment { private boolean mSearchCheck; protected ListmPlaces; @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Populate ListView with Data from Parse //Query All Places final ListView mlist = (ListView)getView().findViewById(R.id.listMain); ParseQuery query = ParseQuery.getQuery("Places"); query.findInBackground(new FindCallback () { @Override public void done(List place, ParseException e) { if (e == null) { mPlaces = place; PlacesAdapter adapter = new PlacesAdapter(getActivity(), mPlaces); mlist.setAdapter(adapter); } else { } } }); }