Endless pagination listview Android with database - android

I need to implement an endless pagination listview in my code, I've searched online and I saw a lot of examples, but none of them is using database, my app does the following:
it connects to an API and retrieves the data with json and show it in a listview, ok that works fine, but I want that listview to have an infinite scroll, like the facebook one.
I don't want anyone to write the code for me, I'm asking to someone guide me on wich is the better way to achieve that, I'll share some of my code, so you can understand:
try {
//Repositorio is my database
Repositorio mRepositorio = new Repositorio(getActivity());
List listaDeClientes = mRepositorio.getClientes();
System.out.println(listaDeClientes);
TextView total = (TextView) rootView.findViewById(R.id.totalClientes);
total.setText(getTotalClientes(mRepositorio.getTotalRegistros("clientes")));
final ArrayAdapter ad = new ClienteViewAdapter(this.getActivity(), R.layout.fragment_cliente_item, listaDeClientes);
ListView lv = (ListView) rootView.findViewById(R.id.listaClientes);
lv.setVerticalFadingEdgeEnabled(true);
lv.setVerticalScrollBarEnabled(true);
lv.setAdapter(ad);
} catch (Exception e) {
e.printStackTrace();
}
return rootView;
}
ClienteViewAdapter:
public class ClienteViewAdapter extends ArrayAdapter<ClienteModel> {
private final LayoutInflater inflater;
private final int resourceId;
public ClienteViewAdapter(Context context, int resource, List<ClienteModel> objects) {
super(context, resource, objects);
this.inflater = LayoutInflater.from(context);
this.resourceId = resource;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
ClienteModel mClienteModel = getItem(position);
view = inflater.inflate(resourceId, parent, false);
TextView tvId = (TextView) view.findViewById(R.id.clienteId);
TextView tvNome = (TextView) view.findViewById(R.id.clienteNome);
TextView tvTipo = (TextView) view.findViewById(R.id.clienteTipo);
tvId.setText(String.valueOf(mClienteModel.getClientes_id()));
tvNome.setText(mClienteModel.getNome());
tvTipo.setText(mClienteModel.getTipo());
return view;
}
}
Model:
public class ClienteModel implements Serializable {
private static final long serialVersionUID = 1L;
private Integer clientes_id;
private Integer id_rm;
private Integer credencial_id;
private String nome;
private String tipo;
private String informacao_adicional;
private String _criado;
private String _modificado;
private String _status;
public Integer getClientes_id() {
return clientes_id;
}
public void setClientes_id(Integer clientes_id) {
this.clientes_id = clientes_id;
}
public Integer getId_rm() {
return id_rm;
}
public void setId_rm(Integer id_rm) {
this.id_rm = id_rm;
}
public Integer getCredencial_id() {
return credencial_id;
}
public void setCredencial_id(Integer credencial_id) {
this.credencial_id = credencial_id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public String getInformacao_adicional() {
return informacao_adicional;
}
public void setInformacao_adicional(String informacao_adicional) {
this.informacao_adicional = informacao_adicional;
}
public String get_criado() {
return _criado;
}
public void set_criado(String _criado) {
this._criado = _criado;
}
public String get_modificado() {
return _modificado;
}
public void set_modificado(String _modificado) {
this._modificado = _modificado;
}
public String get_status() {
return _status;
}
public void set_status(String _status) {
this._status = _status;
}
public static String[] getColunas() {
return Colunas;
}
public static void setColunas(String[] colunas) {
Colunas = colunas;
}
public static String[] Colunas = new String[]{
Coluna.CLIENTES_ID,
Coluna.ID_RM,
Coluna.CREDENCIAL_ID,
Coluna.NOME,
Coluna.TIPO,
Coluna.INFORMACAO_ADICIONAL,
Coluna._CRIADO,
Coluna._MODIFICADO,
Coluna._STATUS
};

Related

Another List inside my Custom Listview with Firebase

I'm trying to display another list inside my custom listview like in the image below. I have successfully display the first three child(name, sport and town). But when i add the coverage child i got this error 'failed to convert value of type arraylist to string' in main activity.
Error message
Failed to convert value of type java.util.ArrayList to String
This is the display im trying to achieve
This is what im trying to achieve
This is my firebase database structure
db structure
I got this code below for my main activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView)findViewById(R.id.cusListView);
mTextView = (TextView)findViewById(R.id.textV);
mRef = FirebaseDatabase.getInstance().getReference().child("Person");
mRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
showData(dataSnapshot);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
private void showData(DataSnapshot dataSnapshot){
ArrayList<PeopleGetSet> array = new ArrayList<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
PeopleGetSet arr = ds.getValue(PeopleGetSet.class);
array.add(arr);
ViewDatabase adapter = new ViewDatabase(this, R.layout.adapter_view_layout, array);
mListView.setAdapter(adapter);
}
}
This it my code for Adapter
public class ViewDatabase extends ArrayAdapter<PeopleGetSet> {
private static final String TAG="ViewDatabase";
private Context mContext;
int mResource;
public ViewDatabase(#NonNull Context context, int resource, #NonNull List<PeopleGetSet> objects) {
super(context, resource, objects);
this.mContext=context;
mResource = resource;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
String name =getItem(position).getName();
String sport =getItem(position).getSport();
String town =getItem(position).getTown();
String Coverage =getItem(position).getCoverage();
PeopleGetSet person = new PeopleGetSet(name,sport, town, Coverage);
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView=inflater.inflate(mResource, parent, false);
TextView tvName = (TextView)convertView.findViewById(R.id.textView);
TextView tvSport = (TextView)convertView.findViewById(R.id.textView2);
TextView tvTown = (TextView)convertView.findViewById(R.id.textView3);
TextView tvCoverage = (TextView)convertView.findViewById(R.id.textView4);
tvName.setText(name);
tvSport.setText(sport);
tvTown.setText(town);
tvCoverage.setText(Coverage);
return convertView;
}
}
And this is my code for Getter and setter
public class PeopleGetSet {
private String name;
private String sport;
private String town;
private String Coverage;
public PeopleGetSet() {
}
public PeopleGetSet(String name, String sport, String town, String Coverage) {
this.name = name;
this.sport = sport;
this.town = town;
this.Coverage = Coverage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSport() {
return sport;
}
public void setSport(String sport) {
this.sport = sport;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getCoverage() {
return Coverage;
}
public void setCoverage(String coverage) {
Coverage = coverage;
}
}
I mean like this:
public class PeopleGetSet {
private String name;
private String sport;
private String town;
private Coverage coverage;
... default code
}
public class Coverage {
private ArrayList<String> names;
... default code
}
Problem is in your Getter Setter class Add Coverage as Hashmap in your PeopleGetSet class. Coverage is not string its array so to read array from firebase you should use HashMap
public class PeopleGetSet {
private String name;
private String sport;
private String town;
private HashMap<String,String> Coverage ;
public PeopleGetSet() {
}
public PeopleGetSet(String name, String sport, String town, HashMap<String, String> Coverage) {
this.name = name;
this.sport = sport;
this.town = town;
this.Coverage = Coverage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSport() {
return sport;
}
public void setSport(String sport) {
this.sport = sport;
}
public String getTown() {
return town;
}
public HashMap<String,String> getCoverage() {
return Coverage;
}
There is a simple way to inflate multiple views inside one ListView. Here's my example code.
public class MyExampleCode extends ArrayAdapter<Object> {
private static final int TYPE_1 = 0;
private static final int TYPE_2 = 1;
private Context context;
private List<Object> objectList;
public MyExampleCode(Context context, List<Object> objectList) {
super(context,layout,objectList);
this.context = context;
this.objectList = objectList;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
if (getItemViewType(position) == TYPE_1) {
PeopleGetSet peopleGetSet = (PeopleGetSet)objectList.get(position);
//handle code for first object, inflate layout and fill it
} else {
Coverage coverage = (Coverage)objectList.get(position);
//handle code for second object, inflate layout and fill it
}
}
#Override
public int getItemViewType(int position) {
if (getItem(position) instanceof PeopleGetSet) {
return TYPE_1;
} else {
return TYPE_2;
}
}
#Nullable
#Override
public Object getItem(int position) {
return objectList.get(position);
}
#Override
public int getCount() {
return objectList.size();
}
}
#Edit
Let update your code
private void showData(DataSnapshot dataSnapshot){
List<Object> array = new ArrayList<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
PeopleGetSet arr = ds.getValue(PeopleGetSet.class);
Coverage arr2 = arr.getCoverage();
array.add(arr);
array.add(arr2);
}
ViewDatabase adapter = new ViewDatabase(this, array);
mListView.setAdapter(adapter);
}

How to apply Indexable ListView with Custom Array Adapter?

I'm trying to apply the Indexable ListView that I found in Github: https://github.com/woozzu/IndexableListView. But my problem is how can I implement it in Custom ArrayAdapter?. I'm using firebase, and I want to show my data in a listview, but my problem is I also want to implement it with Indexable ListView but I can't because there's something error when I implement it because it says not compatible. Is there any method so that I can implement Indexable ListView in my program?
Here's the portion of my code :
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
bookList.clear();
for (DataSnapshot bookSnapshot : dataSnapshot.getChildren()) {
Book books = bookSnapshot.getValue(Book.class);
bookList.add(books);
}
BookList adapter = new BookList(getActivity(),bookList);
ViewBook.setAdapter(adapter);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
BookList.java - the Custom ArrayAdapter
public class BookList extends ArrayAdapter<Book> {
private Activity context;
private List<Book> bookList;
private List<Image> imageList;
private ImageView image;
public BookList(Activity context, List<Book> bookList){
super(context, R.layout.list_layout,bookList);
this.context=context;
this.bookList=bookList;
this.imageList=imageList;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem= inflater.inflate(R.layout.list_layout,null,true);
TextView textViewTitle = (TextView) listViewItem.findViewById(R.id.textViewTitle);
TextView textViewAuthor = (TextView) listViewItem.findViewById(R.id.textViewAuthor);
image = (ImageView) listViewItem.findViewById((R.id.ivUploadImage));
Book books = bookList.get(position);
textViewTitle.setText(books.getBookTitle());
textViewAuthor.setText(books.getAuthorName());
Picasso.with(context).load(books.getBookImageUrl()).into(image);
return listViewItem;
}
}
Book.java
public class Book {
String bookId;
String bookTitle;
String authorName;
String bookDescription;
String bookPublisher;
String bookPages;
String bookISBN;
String bookEdition;
String bookImageUrl;
public Book() {
}
public Book(String bookId, String bookTitle, String authorName, String
bookDescription,String bookPublisher, String bookPages, String bookISBN,
String bookEdition, String bookImageUrl) {
this.bookId = bookId;
this.bookTitle = bookTitle;
this.authorName = authorName;
this.bookDescription = bookDescription;
this.bookPublisher = bookPublisher;
this.bookPages = bookPages;
this.bookISBN = bookISBN;
this.bookEdition = bookEdition;
this.bookImageUrl = bookImageUrl;
}
public String getBookId() {
return bookId;
}
public String getBookTitle() {
return bookTitle;
}
public String getAuthorName() {
return authorName;
}
public String getBookDescription() {
return bookDescription;
}
public String getBookPublisher() {
return bookPublisher;
}
public String getBookPages() {
return bookPages;
}
public String getBookISBN() {
return bookISBN;
}
public String getBookEdition() {
return bookEdition;
}
public String getBookImageUrl() {
return bookImageUrl;
}
}

I have one issue on ListView

I want to implement refine on my app where the item will come from server but in the below Custom_List class code only one item is coming and another item is shown as null.This is screenshot of items.
On this item I am retrieving id,age,height,communities,caste,occupation,education,income,location,pics.
public class RefineCustomList extends ArrayAdapter<String> {
private NetworkImageView imageView;
private ImageLoader imageLoader;
private final String[] ids;
private String[] ages;
private String[] heights;
public String[] communities;
public String[] castes;
public String[] educations;
public String[] occupations;
public String[] incomes;
public String[] pics;
public String[] locations;
public String[] shortlist;
public String[] expressinterest;
private Activity context;
public RefineCustomList(Activity context, String[] ids, String[] ages, String[] heights, String[] communities, String[] castes,
String[] educations, String[] occupations, String[]incomes, String[]pics, String[] locations,
String[] shortlist, String[] expressinterest) {
super(context, R.layout.list_view_layout,ids);
this.ids = ids;
this.ages = ages;
this.heights = heights;
this.communities = communities;
this.castes = castes;
this.educations = educations;
this.occupations = occupations;
this.incomes = incomes;
this.pics = pics;
this.locations = locations;
this.context = context;
this.shortlist = shortlist;
this.expressinterest = expressinterest;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.refine_custom_list, null, true);
String url1 = "https://www.maangal.com/thumb/thumb_";
String url =url1+pics[position];
imageView = (NetworkImageView) listViewItem.findViewById(R.id.offer_image);
imageLoader = CustomVolleyRequest.getInstance(this.getContext()).getImageLoader();
imageLoader.get(url, ImageLoader.getImageListener(imageView,R.drawable.image,android.R.drawable.ic_dialog_alert));
imageView.setImageUrl(url,imageLoader);
TextView textViewId = (TextView) listViewItem.findViewById(R.id.textViewId);
TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
textViewId.setText(ids[position]);
textViewName.setText( ages[position]+" years"+" , "+heights[position]+" cm"+", "+communities[position]+" : "+castes[position]+" , "+educations[position]+" , "+occupations[position]+" , "+incomes[position]+", "+locations[position]);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(), BlankActivity.class);
Toast.makeText(getContext(), ids[position], Toast.LENGTH_LONG).show();
i.putExtra("id", ids[position]);
v.getContext().startActivity(i);
}
});
Button btnSort =(Button) listViewItem.findViewById(R.id.btnshort);
btnSort.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(),"Shortlisted",Toast.LENGTH_LONG).show();
}
});
Button btnChat =(Button) listViewItem.findViewById(R.id.btnchat);
btnChat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(),"Chatting",Toast.LENGTH_LONG).show();
}
});
Button declineButton = (Button)listViewItem.findViewById(R.id.declineButton);
declineButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(),"Decline",Toast.LENGTH_LONG).show();
}
});
return listViewItem;
}
}
This is the parsing code
public class RefineActivity extends FragmentActivity {
SessionManager session;
String email;
public String JSON_URL;
private ListView listView;
Button rfb;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.refine_activity);
// Session class instance
session = new SessionManager(this);
// get user data from session
HashMap<String, String> user = session.getUserDetails();
email = user.get(SessionManager.KEY_EMAIL);
Log.e("email==========>", email);
//JSON_URL = "http://10.0.2.2/xp/ei_sent_pending.php?matri_id="+email;
listView = (ListView) findViewById(R.id.listView);
rfb = (Button) findViewById(R.id.refineBtn);
rfb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
RefineFragment ls_fragment = new RefineFragment();
ls_fragment.show(fragmentManager, "simple fragment");
}
});
Intent intent = getIntent();
final String response = getIntent().getExtras().getString("res");
Log.e("responde rfi", response);
showJSON(response);
}
protected void showJSON(String json) {
ParseJSON pj = new ParseJSON(json);
pj.parseJSON();
RefineCustomList cl = new RefineCustomList(this, ParseJSON.ids, ParseJSON.ages, ParseJSON.heights, ParseJSON.communities, ParseJSON.castes, ParseJSON.educations, ParseJSON.occupations, ParseJSON.incomes, ParseJSON.pics, ParseJSON.locations, ParseJSON.shortlist, ParseJSON.expressinterest);
listView.setAdapter(cl);
}
}
This is the Log where the item data is showing
responde rfi: {"result":[{"id":"Mgl11638","age":"21","height":"160","caste":"Brahmin","community":"Kumaoni","education":"MA","occupation":"Not Working","income":"Will tell later","pic":"Mgl11638.jpg","location":"Almora"},{"id":"Mgl16111","age":"22","height":"160","caste":"Brahmin","community":"Kumaoni","education":"B.Sc","occupation":"Student","income":"Will tell later","pic":"","location":"Almora"},{"id":"Mgl11658","age":"22","height":"154","caste":"Brahmin","community":"Kumaoni","education":"Undergraduate","occupation":"Student","income":"Will tell later","pic":"","location":"Lucknow"},{"id":"Mgl11621","age":"21","height":"134","caste":"Brahmin","community":"Kumaoni","education":"MA","occupation":"Not Working","income":"No income","pic":"","location":"Bareilly"}]}
Why do you use too much of Arrays inside an adapter? Just follow these steps.
Put all your strings inside an Object as single fields.
Pass that object as a parameter into your adapter from your Activity.
Fetch the details from that object in your adapter.
Then the adapter will automatically fetch you multiple data and populate into the list view. And my kind advice is to extend the class as BaseAdapter instead of ArrayAdapter
This is your object. I created it exclusively for you. Create a new java class(not an activity, just a .java file) and put this code inside.
public class DetailsObject implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String age;
private String height;
public String community;
public String caste;
public String education;
public String occupation;
public String income;
public byte[] pic;
public String location;
public String shortlist;
public String expressinterest;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getCommunity() {
return community;
}
public void setCommunity(String community) {
this.community = community;
}
public String getCaste() {
return caste;
}
public void setCaste(String caste) {
this.caste = caste;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getOccupation() {
return occupation;
}
public void setOccupation(String occupation) {
this.occupation = occupation;
}
public String getIncome() {
return income;
}
public void setIncome(String income) {
this.income = income;
}
public byte[] getPic() {
return pic;
}
public void setPic(byte[] pic) {
this.pic = pic;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getShortlist() {
return shortlist;
}
public void setShortlist(String shortlist) {
this.shortlist = shortlist;
}
public String getExpressinterest() {
return expressinterest;
}
public void setExpressinterest(String expressinterest) {
this.expressinterest = expressinterest;
}
}
In your adapter class change extends ArrayAdapter<String> to extends BaseAdapter, change all the String[] to String and in the constructor, juzt pass (Context context, DetailsObject detailObject) as parameter. And in your activity call the adapter like below:
RefineCustomList refineCustomList;
refineCustomList = new RefineCustomList(MainActivity.this,detailObject);
yourListView.setAdapter(refineCustomList);
Thats it..

Retrofit 2 in a CustomView

In my code I am using an internet example that work fine using Retrofit2 and custom recyclerview but I decide to use this application in android starting at version 4.1.2 so the recyclerview doesn't work there. So, there is a possibility to change the custom recyclerview to a custom listview?
Lista_productos.java
public class Lista_productos extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private List<Elementos_fila_productos> elementos;
private RecyclerviewAdapter adapter;
private ApiInterface apiInterface;
static LayoutInflater layoutInflater;
static PopupWindow popupWindow;
static TextView nombre_seleccionado;
static FrameLayout frameLayout;
static String cantidad_deseada;
static char hola;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_productos);
recyclerView = (RecyclerView)findViewById(R.id.recyclerview_tablillas);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
if(getIntent().getExtras() != null){
String type = getIntent().getExtras().getString("type");
buscarInformacion(type);
}
}
public void buscarInformacion(String type){
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<List<Elementos_fila_productos>> call = apiInterface.getElementosInfo(type);
call.enqueue(new Callback<List<Elementos_fila_productos>>() {
#Override
public void onResponse(Call<List<Elementos_fila_productos>> call, Response<List<Elementos_fila_productos>> response) {
elementos = response.body();
adapter = new RecyclerviewAdapter(elementos, Lista_productos.this);
recyclerView.setAdapter(adapter);
}
#Override
public void onFailure(Call<List<Elementos_fila_productos>> call, Throwable t) {
final AlertDialog.Builder builder = new AlertDialog.Builder(Lista_productos.this, R.style.Theme_AppCompat_Light_Dialog_Alert);
builder.setCancelable(true);
builder.setTitle("Error!");
builder.setMessage("mensaje");
builder.setIcon(R.drawable.ic_launcher);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}
ListaComprasAdapter.java
public class ListaComprasAdapter extends BaseAdapter {
ArrayList<String> nombre;
ArrayList<String> cantidad;
ArrayList<String> precio;
ArrayList<String> total;
Context mContext;
//constructor
public ListaComprasAdapter(Context mContext, ArrayList<String> nombre, ArrayList<String> cantidad, ArrayList<String> precio, ArrayList<String> total) {
this.mContext = mContext;
this.nombre = nombre;
this.cantidad = cantidad;
this.precio = precio;
this.total = total;
}
public int getCount() {
return nombre.size();
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View arg1, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.custom_lista_de_compras, viewGroup, false);
TextView Nombre = (TextView) row.findViewById(R.id.nombre_del_producto);
TextView Cantidad = (TextView) row.findViewById(R.id.cantidad);
TextView Precio = (TextView) row.findViewById(R.id.precio);
TextView Total = (TextView) row.findViewById(R.id.precio_total_producto);
Nombre.setText(nombre.get(position));
Cantidad.setText(cantidad.get(position));
Precio.setText(precio.get(position));
Total.setText(total.get(position));
return row;
}
}
Elementos_fila_productos.java : the elements of each row
public class Elementos_fila_productos {
#SerializedName("ID")
private String ID;
#SerializedName("Caracteristicas")
private String Caracteristicas;
#SerializedName("Precio")
private int Precio;
#SerializedName("Grosor")
private String Grosor;
#SerializedName("Disponibles")
private int Disponible;
#SerializedName("Imagen")
private String Imagen;
public String getGrosor() {
return Grosor;
}
public String getID() {
return ID;
}
public String getCaracteristicas() {
return Caracteristicas;
}
public int getPrecio() {
return Precio;
}
public int getDisponible() {
return Disponible;
}
public String getImagen() {
return Imagen;
}
}
ApiInterface.java
public interface ApiInterface {
#GET("tablillas2.php")
//revisar en el caso de que no funcione
Call<List<Elementos_fila_productos>> getElementosInfo(#Query("item_type") String item_type);
}
ApiClient.java
public class ApiClient {
public static final String Base_Url = "http://creadorjuancarloscfapptablilla.esy.es/appTablillas/";
public static Retrofit retrofit;
public static Retrofit getApiClient(){
if (retrofit==null){
retrofit = new Retrofit.Builder().baseUrl(Base_Url).addConverterFactory(GsonConverterFactory.create()).build();
}
return retrofit;
}
}
It looks like RecyclerView does work for Android 4.1.2. See the accepted answer for this question: Would recyclerview work on an android device with Jellybean?

One ListView Receiving Data from Multiple Class

I am looking for something like this:
several <ItemTemplate> in one ListView.
But it was in .ASP and above my level.
What I need
Class Vitals: vTime, BP, Heart Rate, Respirations per Minute, etc.
Class Medications: mTime, RxName, RxRoute, RxDose, RxDoseUnit, etc.
Class Procedures: pTime, Intubation, IV insertion, Defibrillation, etc.
Classes Vitals, Medications and Procedures to be based on user input that inject in to a ListView (sorted chronologically). A "Many-to-One" if I may.
I've went through hours of "CustomAdapter & ListView" tutorials, code samples, walkthroughs.
Here is my current code (trashed and scattered) to show that I am actively working towards a solution:
/*
* Created by SwaLayS on 2/19/2015.
*/
public class VitalAdapter extends BaseAdapter {
private ArrayList<VitalItem> vitalData;
private LayoutInflater layoutInflater;
public VitalAdapter(Context acontext, ArrayList<VitalItem> vitalData){
this.vitalData=vitalData;
layoutInflater=LayoutInflater.from(acontext);
}
#Override
public int getCount() {
return vitalData.size();
}
#Override
public Object getItem(int position) {
return vitalData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null){
convertView = layoutInflater.inflate(R.layout.vital_view_children,null);
holder = new ViewHolder();
}
}
public class VitalView extends RelativeLayout {
private TextView vTimeTV;
// private TextView vPTATV;
private TextView vRateTV;
private TextView vOxySatTV;
private TextView vSysBPTV;
private TextView vDiaBPTV;
private TextView vRespRateTV;
private TextView vRespEffortTV;
//private TextView vMethodBPTV;
public static VitalView inflate(ViewGroup parent){
VitalView vitalView = (VitalView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.vital_view,parent,false);
return vitalView;
}
public VitalView(Context c){
this(c,null);
}
public VitalView(Context context, AttributeSet attrs){
this(context, attrs,0);
}
public VitalView(Context context, AttributeSet attrs, int defStyle){
super(context,attrs,defStyle);
LayoutInflater.from(context).inflate(R.layout.vital_view_children, this,true);
setupChildren();
}
private void setupChildren(){
vTimeTV = (TextView)findViewById(R.id.vTime);
// vPTATV = (TextView)findViewById(R.id.vPTA);
vRateTV = (TextView) findViewById(R.id.vBPM);
vOxySatTV = (TextView) findViewById(R.id.vOsat);
vSysBPTV = (TextView) findViewById(R.id.vSystolic);
vDiaBPTV = (TextView)findViewById(R.id.vDiastolic);
vRespRateTV = (TextView) findViewById(R.id.vRespRate);
vRespEffortTV = (TextView)findViewById(R.id.vRespEffort);
// vMethodBPTV = (TextView)findViewById(R.id.vMethodBP
}
public void setVital(VitalItem vital){
//vTimeTV.setText(vital.get);
}
}
public class VitalItem {
private String vTime;
// private String vPTA;
private String vRate;
private String vOxySat;
private String vSysBP;
private String vDiaBP;
private String vRespRate;
private String vRespEffort;
// private String vMethodBP;
public VitalItem(String Time, String Rate, String OxySat, String SysBP, String DiaBp, RespRate, String RespEffort){
super();
vTime=Time;
// vPTA=PTA;
vRate=Rate;
vOxySat = OxySat;
vSysBP = SysBP;
vDiaBP = DiaBP;
vRespRate = RespRate;
vRespEffort=RespEffort;
//vMethodBP=MethodBP;
}
public String getvTime() {
return vTime;
}
public void setvTime(String vTime) {
this.vTime = vTime;
}
// public String getvPTA() {
// return vPTA;
// }
// public void setvPTA(String vPTA) {
// this.vPTA = vPTA;
// }
public String getvRate() {
return vRate;
}
public void setvRate(String vRate) {
this.vRate = vRate;
}
public String getvOxySat() {
return vOxySat;
}
public void setvOxySat(String vOxySat) {
this.vOxySat = vOxySat;
}
public String getvSysBP() {
return vSysBP;
}
public void setvSysBP(String vSysBP) {
this.vSysBP = vSysBP;
}
public String getvDiaBP() {
return vDiaBP;
}
public void setvDiaBP(String vDiaBP) {
this.vDiaBP = vDiaBP;
}
public String getvRespRate() {
return vRespRate;
}
public void setvRespRate(String vRespRate) {
this.vRespRate = vRespRate;
}
public String getvRespEffort() {
return vRespEffort;
}
public void setvRespEffort(String vRespEffort) {
this.vRespEffort = vRespEffort;
}
// public String getvMethodBP() {
// return vMethodBP;
//}
// public void setvMethodBP(String vMethodBP) {
// this.vMethodBP = vMethodBP;
//
}
}
I'd appreciate any and everything;
I'm working on a NEMSIS . org project;
I may even be searching with the wrong search terms for what I need.
All help is appreciated
have you try the getViewTypeCount() method in adapter,
it can define different itemView for your different data types.
for your case you need to define three layout items .
search some demos,it may help you .

Categories

Resources