How to apply Indexable ListView with Custom Array Adapter? - android

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;
}
}

Related

Recyclerview doesn't retrieve data from firebase

I have added data in firebase. All i have to do is get that data in recyclerview. i have done this many type, but this time it is not showing and i don't know the reason because it is not showing in log. Can any one help?
here's my Activity where the RV is located
rvsalonlist is recyclerview
public void firebasedata() {
FirebaseRecyclerOptions<salonList> options =
new FirebaseRecyclerOptions.Builder<salonList>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("salon"), salonList.class)
.build();
adapter = new SalonListAdapter(options);
rvSalonList.setAdapter(adapter);
adapter.startListening();
}
This is the adapter
public class SalonListAdapter extends FirebaseRecyclerAdapter<salonList,SalonListAdapter.myviewholder> {
public SalonListAdapter(#NonNull FirebaseRecyclerOptions<salonList> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull myviewholder holder, int position, #NonNull salonList model) {
holder.tvSalonName.setText(String.valueOf(model.getSalonName()));
holder.tvSalonAddress.setText(String.valueOf(model.getSalonAddresss()));
Glide.with(holder.ivSalonImage.getContext()).load(model.getImageUrl()).into(holder.ivSalonImage);
}
#NonNull
#Override
public myviewholder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_salon,parent,false);
return new myviewholder(view);
}
class myviewholder extends RecyclerView.ViewHolder{
ImageView ivSalonImage;
TextView tvSalonName, tvSalonMobileNumber, tvSalonAddress;
public myviewholder(#NonNull View itemView) {
super(itemView);
ivSalonImage = itemView.findViewById(R.id.ivSalonImage);
tvSalonName = itemView.findViewById(R.id.tvSalonName);
tvSalonMobileNumber = itemView.findViewById(R.id.tvSalonMobileNumber);
tvSalonAddress = itemView.findViewById(R.id.tvSalonAddress);
}
}
}
Heres the model class .
[![public class salonList {
private String imageUrl, salonName, ownerName, salonEmail, salonMobileNumber, salonAddresss, salonOpenTime, salonCloseTime;
public salonList() {
}
public salonList(String imageUrl, String salonName, String ownerName, String salonEmail, String salonMobileNumber, String salonAddresss, String salonOpenTime, String salonCloseTime) {
this.imageUrl = imageUrl;
this.salonName = salonName;
this.ownerName = ownerName;
this.salonEmail = salonEmail;
this.salonMobileNumber = salonMobileNumber;
this.salonAddresss = salonAddresss;
this.salonOpenTime = salonOpenTime;
this.salonCloseTime = salonCloseTime;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getSalonName() {
return salonName;
}
public void setSalonName(String salonName) {
this.salonName = salonName;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getSalonEmail() {
return salonEmail;
}
public void setSalonEmail(String salonEmail) {
this.salonEmail = salonEmail;
}
public String getSalonMobileNumber() {
return salonMobileNumber;
}
public void setSalonMobileNumber(String salonMobileNumber) {
this.salonMobileNumber = salonMobileNumber;
}
public String getSalonAddresss() {
return salonAddresss;
}
public void setSalonAddresss(String salonAddresss) {
this.salonAddresss = salonAddresss;
}
public String getSalonOpenTime() {
return salonOpenTime;
}
public void setSalonOpenTime(String salonOpenTime) {
this.salonOpenTime = salonOpenTime;
}
public String getSalonCloseTime() {
return salonCloseTime;
}
public void setSalonCloseTime(String salonCloseTime) {
this.salonCloseTime = salonCloseTime;
}
}
Database Screenshot
your model class variable names and firebase attributes name are not same. use same name in both places.
for example in firebase use salonName instead of name. similarly for other attributes as well
The names have to be identical
For eg, you have ownerName in the class but ownername in the database. Those should all be identical to the ones you have in your class.

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);
}

DatabaseException: Can't convert object of type java.lang.String to type java.lang.String to type

My firebase Data Structure
My MainActivity code...
public class MainActivity extends AppCompatActivity {
ListView reviewListView;
DatabaseReference reviewDatabaseReference;
//FirebaseReview1 fr;
CustomReviewAdapter adapter;
ArrayList<UserReview> userReviews = new ArrayList<>();
TextView text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
reviewListView = (ListView) findViewById(R.id.reviewList);
//reviewDatabaseReference = FirebaseDatabase.getInstance().getReference();
//Query q = reviewDatabaseReference.child("Reviews").child("Mobile").child("Apple").child("iPhone 8 Plus").orderByChild("time");
//fr = new FirebaseReview1(q);
adapter = new CustomReviewAdapter(this,retrieve());
reviewListView.setAdapter(adapter);
}catch (Exception e){
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_SHORT).show();
}
}
private void fetchReviewData(DataSnapshot dataSnapshot){
try{
userReviews.clear();
for(DataSnapshot ds: dataSnapshot.getChildren()){
UserReview userReview1 = ds.getValue(UserReview.class);
userReviews.add(userReview1);
}}catch (Exception e){
text = (TextView)findViewById(R.id.text);
text.setText(e.toString());
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_SHORT).show();
}
}
public ArrayList<UserReview> retrieve()
{
try {
reviewDatabaseReference = FirebaseDatabase.getInstance().getReference();
Query q = reviewDatabaseReference.child("Reviews").child("Mobile").child("Apple").child("iPhone 8 Plus").orderByChild("time");
q.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
fetchReviewData(dataSnapshot);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
fetchReviewData(dataSnapshot);
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}catch (Exception e){
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
}
return userReviews;
}
My UserReview class
public class UserReview {
String phone;
String name;
String rate;
String title;
String review;
String time;
public UserReview(){}
public UserReview(String phone,String name,String rate,String title,String review,String time){
this.phone = phone;
this.name = name;
this.rate = rate;
this.title = title;
this.review = review;
this.time = time;
}
public String getPhone() { return phone; }
public String getName() {
return name;
}
public String getRate() {return rate;}
public String getTitle() {
return title;
}
public String getReview() {
return review;
}
public String getTime() {return time;}
}
My CustomeAdapter
public class CustomReviewAdapter extends BaseAdapter{
Context c;
ArrayList<UserReview> userReviews;
public CustomReviewAdapter(Context c, ArrayList<UserReview> userReviews){
this.c = c;
this.userReviews = userReviews;
}
#Override
public int getCount() {
return userReviews.size();
}
#Override
public Object getItem(int position) {
return userReviews.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(c).inflate(R.layout.review_list,parent,false);
}
TextView starTextView = (TextView)convertView.findViewById(R.id.starTextView);
TextView titleTextView = (TextView)convertView.findViewById(R.id.titleTextView);
TextView nameTextView = (TextView)convertView.findViewById(R.id.nameTextView);
TextView reviewTextView = (TextView)convertView.findViewById(R.id.reviewTextView);
UserReview ur = (UserReview)this.getItem(position);
starTextView.setText(ur.getRate());
titleTextView.setText(ur.getTitle());
nameTextView.setText(ur.getName());
reviewTextView.setText(ur.getReview());
return convertView;
}
}
I am trying to retrieve data but it giving error
DatabaseException: Can't convert object of type java.lang.String to type java.lang.String to type
Since you're listening to onChildAdded the snapshot already contains exactly one child. So your fetchData doesn't need to loop over the snapshot's children.
private void fetchReviewData(DataSnapshot dataSnapshot){
UserReview userReview = dataSnapshot.getValue(UserReview.class);
userReviews.add(userReview);
}

how to retrieve all data from firebase and display on listview android?

I am making an android app ,which is get order from customers,but i faced a problem . I am trying to Retrieve Data from Firebase and display in a list view. I can get the data back from Firebase but when it displays in the listview it just displays one data in many times. I want to be displayed on one line for each record. Can anyone see where i am going wrong??
Database Image
ListView Image
OrderHistory
public class OrderHistory
{
String ammount,photoId,trxId,name,copy,photoSize,date;
public OrderHistory(String name,String photoId,String trxId,String copy,String photoSize,String ammount,String date)
{
this.name = name;
this.ammount = ammount;
this.photoId = photoId;
this.copy = copy;
this.photoSize = photoSize;
this.trxId = trxId;
this.date = date;
}
public String getAmmount() {
return ammount;
}
public void setAmmount(String ammount) {
this.ammount = ammount;
}
public String getPhotoId() {
return photoId;
}
public void setPhotoId(String photoId) {
this.photoId = photoId;
}
public String getTrxId() {
return trxId;
}
public void setTrxId(String trxId) {
this.trxId = trxId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCopy() {
return copy;
}
public void setCopy(String copy) {
this.copy = copy;
}
public String getPhotoSize() {
return photoSize;
}
public void setPhotoSize(String photoSize) {
this.photoSize = photoSize;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
OrderHistoryAdapter
public class OrderHistoryAdapter extends BaseAdapter {
private List<OrderHistory> orderHistories;
Context context;
public OrderHistoryAdapter(Context context, List<OrderHistory> myOrderInformations) {
this.context = context;
this.orderHistories = myOrderInformations;
}
#Override
public int getCount() {
return orderHistories.size();
}
#Override
public Object getItem(int position) {
return orderHistories.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.show_my_order_history, parent, false);
final TextView txtName, txtdate, txtPhotoId, trxId,txtAmount,txtPhotoSize,txtCopy;
txtName = (TextView)view.findViewById(R.id.txtName);
txtdate = (TextView)view.findViewById(R.id.txtDate);
txtPhotoId = (TextView)view.findViewById(R.id.txtPhotoId);
trxId = (TextView)view.findViewById(R.id.txtTrx);
txtAmount = (TextView)view.findViewById(R.id.txtAmount);
txtPhotoSize = (TextView)view.findViewById(R.id.txtSize);
txtCopy = (TextView)view.findViewById(R.id.txtCopy);
txtName.setText(orderHistories.get(position).getName());
txtdate.setText(orderHistories.get(position).getDate());
txtPhotoId.setText(orderHistories.get(position).getPhotoId());
trxId.setText(orderHistories.get(position).getTrxId());
txtAmount.setText(orderHistories.get(position).getAmmount());
txtCopy.setText(orderHistories.get(position).getCopy());
txtPhotoSize.setText(orderHistories.get(position).getPhotoSize());
return view;
}
}
OrderHistoryList
public class OrderHistoryList extends AppCompatActivity
{
private DatabaseReference databaseReference;
private List<OrderHistory> orderHistories;
private static String phoneNumber;
private ListView listView;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_my_order);
Firebase.setAndroidContext(this);
listView = (ListView)findViewById(R.id.listView);
getAllOrderFromFirebase();
}
private void getAllOrderFromFirebase()
{
orderHistories = new ArrayList<>();
databaseReference = FirebaseDatabase.getInstance().getReference("order");
String phone = getIntent().getExtras().getString("phone");
databaseReference.orderByChild("phone").equalTo(phone).addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String amount, photoId, trxId, name, copy, photoSize, date;
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
name = snapshot.child("name").getValue(String.class);
photoId = snapshot.child("photoId").getValue(String.class);
amount = snapshot.child("totalAmount").getValue(String.class);
trxId = snapshot.child("trxId").getValue(String.class);
photoSize = snapshot.child("photoSize").getValue(String.class);
date = snapshot.child("date").getValue(String.class);
copy = snapshot.child("totalCopy").getValue(String.class);
orderHistories.add(new OrderHistory(name, photoId, trxId, copy, photoSize, amount, date));
}
OrderHistoryAdapter adapter;
adapter = new OrderHistoryAdapter(OrderHistoryList.this, orderHistories);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
I guess your problem is by the way you refer to your data so instead of this
databaseReference = FirebaseDatabase.getInstance().getReference("order");
use this
databaseReference = FirebaseDatabase.getInstance().getReference().child("order");
and you didn't use a query object to query your database reference
so now you don't query directly from databaseReference like the way you did it
instead you do this:
Query query=databaseReference.orderByChild("phone").equalTo(phone);
once you have a query that fits you now add on child listener and continue the rest of your code:
query.addChildEventListener(new ChildEventListener() {
//the rest of your code goes here(on child added/changed/......)
)};

Endless pagination listview Android with database

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
};

Categories

Resources