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..
Related
I am writing this code in my RecyclerViewAdapter and I have a separate Java File from which I want to set an ItemOnClickListener and Context for my adapter class. However, they come out as null. This is the method from the Java File for the recyclerView.
public void update(){
userRef.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
String imageUrl;
String name;
String extra;
String ready;
String ingredients;
String id;
List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();
for( int i = 0; i < list.size(); i++){
DocumentSnapshot documentSnapshot = list.get(i);
if(documentSnapshot.exists()){
Map<String, Object> favFood = documentSnapshot.getData();
name = favFood.get(KEY_NAME).toString();
imageUrl = favFood.get(KEY_URL).toString();
extra = favFood.get(KEY_XTRAINFO).toString();
ready = favFood.get(KEY_READY).toString();
Log.d("TAGG", ready);
ingredients = favFood.get(KEY_INGREDIENTS).toString();
id = favFood.get(KEY_ID).toString();
allFavoritedFoods.add(new FoodItem(imageUrl, name, ready, extra, ingredients, id, FirebaseAuth.getInstance().getCurrentUser().getUid()));
}
}
foodAdapter = new FoodAdapter(allFavoritedFoods, FavItem.this);
recyclerView.setAdapter(foodAdapter);
foodAdapter.setOnItemClickListener(FavItem.this);
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
}
});
}
This is for the relevant code from the Adapter Class:
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.ViewHolder> {
private ArrayList<FoodItem> foodItems;
private Context context;
static String id;
private OnItemClickListener mListener;
public interface OnItemClickListener{
void onItemClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener){
mListener = listener;
}
#Override
public int getItemCount() {
return foodItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView name, readyTime, ingredients, extraInfo;
public ImageView picture;
Button favBtn;
FirebaseFirestore db = FirebaseFirestore.getInstance();
public static final String KEY_URL = "imageUrl", KEY_INGREDIENTS = "ingredients", KEY_READY = "ready";
public static final String KEY_NAME = "name";
public static final String KEY_XTRAINFO = "info";
public static final String KEY_ID = "id";
public static final String KEY_FAV = "favorited";
//public Button favBtn;
public ViewHolder(View itemView){
super(itemView);
name = itemView.findViewById(R.id.title);
picture = itemView.findViewById(R.id.thumbnail);
readyTime = itemView.findViewById(R.id.readyInMinutes);
ingredients = itemView.findViewById(R.id.ingredients);
extraInfo = itemView.findViewById(R.id.extraInfo);
itemView.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
if(mListener!=null){
int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION){
mListener.onItemClick(position);
}
}
}
});
favBtn = itemView.findViewById(R.id.favBtn);
favBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
FoodItem foodItem = foodItems.get(position);
Map<String, Object> favFood = new HashMap<>();
favFood.put(KEY_NAME, foodItem.getTitle());
favFood.put(KEY_URL, foodItem.getImageUrl());
favFood.put(KEY_ID, foodItem.getId());
favFood.put(KEY_INGREDIENTS, foodItem.getIngredients());
favFood.put(KEY_READY, foodItem.getReadyTime());
favFood.put(KEY_XTRAINFO, foodItem.getExtraInfo());
db.collection(FirebaseAuth.getInstance().getCurrentUser().getEmail()).document(id+"").set(favFood)
.addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Toast.makeText(itemView.getContext(), "Added to Favorites", Toast.LENGTH_SHORT);
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(itemView.getContext(), "Deleted From Favorites", Toast.LENGTH_SHORT);
Log.d("Error in Storing", e.toString());
}
});
}
});
}
}
public FoodAdapter(ArrayList<FoodItem> foodItems, Context context){
this.foodItems = foodItems;
this.context = context;
}
For the MainActivity.java, this worked, but foodAdapter.setOnItemClickListener(MainActivity.this);. But it isn't working similarly to the other Java File.
For the context what would I put and what would I put for the onItemClickListener for the method from the other Java File?
If you are writing update() method inside a fragment, pass context as follows.
foodAdapter = new FoodAdapter(allFavoritedFoods, getActivity());
If you are writing update() method inside an activity, pass context as follows.(assume activity name is MainActivity)
foodAdapter = new FoodAdapter(allFavoritedFoods, MainActivity.this);
I have already Read Data from Sqlite database in recyclerview
But when user click next_button it fetch more data from same row using BANK_ID
In First Activity I have read some data from sqlite database in recyclerView And When user click next_button its fetch more data from sqlite database using same row I've already pass BANK_ID which is autoIncrement
Here is my code...
DataModel Class
public class DataModel {
public String BANK_ID;
public String id;
public String farmer_insure_name;
public String farmer_bank_hypo;
public String farmer_name;
public String village;
public String taluka;
public String district;
public String tagging_date;
public String tag_no;
public String animal_species;
public String animal_breed;
public String body_color;
public String shape_right;
public String shape_left;
public String tail_switch;
public String other_marks;
public String prag_status;
public String lactations;
public String milk_qty;
public String sum_insured;
public String tag_photo;
public String head_photo;
public String left_photo;
public String right_photo;
public String farmer_photo;
public String getBANK_ID() {
return BANK_ID;
}
public void setBANK_ID(String BANK_ID) {
this.BANK_ID = BANK_ID;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFarmer_insure_name() {
return farmer_insure_name;
}
public void setFarmer_insure_name(String farmer_insure_name) {
this.farmer_insure_name = farmer_insure_name;
}
public String getFarmer_bank_hypo() {
return farmer_bank_hypo;
}
public void setFarmer_bank_hypo(String farmer_bank_hypo) {
this.farmer_bank_hypo = farmer_bank_hypo;
}
public String getFarmer_name() {
return farmer_name;
}
public void setFarmer_name(String farmer_name) {
this.farmer_name = farmer_name;
}
public String getVillage() {
return village;
}
public void setVillage(String village) {
this.village = village;
}
public String getTaluka() {
return taluka;
}
public void setTaluka(String taluka) {
this.taluka = taluka;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getTagging_date() {
return tagging_date;
}
public void setTagging_date(String tagging_date) {
this.tagging_date = tagging_date;
}
public String getTag_no() {
return tag_no;
}
public void setTag_no(String tag_no) {
this.tag_no = tag_no;
}
public String getAnimal_species() {
return animal_species;
}
public void setAnimal_species(String animal_species) {
this.animal_species = animal_species;
}
public String getAnimal_breed() {
return animal_breed;
}
public void setAnimal_breed(String animal_breed) {
this.animal_breed = animal_breed;
}
public String getBody_color() {
return body_color;
}
public void setBody_color(String body_color) {
this.body_color = body_color;
}
public String getShape_right() {
return shape_right;
}
public void setShape_right(String shape_right) {
this.shape_right = shape_right;
}
public String getShape_left() {
return shape_left;
}
public void setShape_left(String shape_left) {
this.shape_left = shape_left;
}
public String getTail_switch() {
return tail_switch;
}
public void setTail_switch(String tail_switch) {
this.tail_switch = tail_switch;
}
public String getOther_marks() {
return other_marks;
}
public void setOther_marks(String other_marks) {
this.other_marks = other_marks;
}
public String getPrag_status() {
return prag_status;
}
public void setPrag_status(String prag_status) {
this.prag_status = prag_status;
}
public String getLactations() {
return lactations;
}
public void setLactations(String lactations) {
this.lactations = lactations;
}
public String getMilk_qty() {
return milk_qty;
}
public void setMilk_qty(String milk_qty) {
this.milk_qty = milk_qty;
}
public String getSum_insured() {
return sum_insured;
}
public void setSum_insured(String sum_insured) {
this.sum_insured = sum_insured;
}
public String getTag_photo() {
return tag_photo;
}
public void setTag_photo(String tag_photo) {
this.tag_photo = tag_photo;
}
public String getHead_photo() {
return head_photo;
}
public void setHead_photo(String head_photo) {
this.head_photo = head_photo;
}
public String getLeft_photo() {
return left_photo;
}
public void setLeft_photo(String left_photo) {
this.left_photo = left_photo;
}
public String getRight_photo() {
return right_photo;
}
public void setRight_photo(String right_photo) {
this.right_photo = right_photo;
}
public String getFarmer_photo() {
return farmer_photo;
}
public void setFarmer_photo(String farmer_photo) {
this.farmer_photo = farmer_photo;
}
}
DatabaseHelper Class
public class DatabaseHelper extends SQLiteOpenHelper {
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
public static final String DATABASE_NAME = "SNVINSURANCE.db";
public static final String TABLE_NAME_IMAGES = "images_table";
private static final int DATABASE_VERSION = 1;
private static final String IMAGES_TABLE = "ImagesTable";
public static final String COLUMN_ID = "ID";
public static final String BANK_COLUMN = "BANK_NAME";
public static final String INSURED_COLUMN = "INSURED_NAME";
public static final String BNAKHYPO_COLUMN = "BANKHYPO_NAME";
public static final String COLUMN_STATUS = "status";
public static final String FARMERNAME_ID = "ID";
public static final String SNV_ID = "SNV";
public static final String FARMERNAME_COLUMN = "FARMER_NAME";
public static final String VILLAGE_COLUMN = "VILLAGE";
public static final String TALUKA_COLUMN = "TALUKA";
public static final String DISTRICT_COLUMN = "DISTRICT";
public static final String TAGGING_DATE_COLUMN = "TAGGING_DATE";
public static final String ANIMAL_ID = "ID";
public static final String TAG_COLUMN = "TAG";
public static final String ANIMAL_SPECIES_COLUMN = "ANIMAL_SPECIES";
public static final String ANIMAL_BREED_COLUMN = "ANIMAL_BREED";
public static final String ANIMAL_BODY_COLOR_COLUMN = "ANIMAL_BODY_COLOR";
public static final String ANIMAL_SHAPE_RIGHT_COLUMN = "ANIMAL_SHAPE_RIGHT";
public static final String ANIMAL_SHAPE_LEFT_COLUMN = "ANIMAL_SHAPE_LEFT";
public static final String ANIMAL_SWITCH_OF_TAIL_COLUMN = "ANIMAL_SWITCH_OF_TAIL";
public static final String AGE_COLUMN = "AGE";
public static final String ANIMAL_OTHER_MARKS_COLUMN = "ANIMAL_OTHER_MARKS";
public static final String PRAG_STATUS_COLUMN = "PRAG_STATUS";
public static final String NUMBER_OF_LACTATION_COLUMN = "NUMBER_OF_LACTATION";
public static final String CURRENT_MILK_COLUMN = "CURRENT_MILK";
public static final String SUM_INSURED_COLUMN = "SUM_INSURED";
public static final String TAG_IMAGE_COLUMN = "TAG_IMAGE";
public static final String HEAD_IMAGE_COLUMN = "HEAD_IMAGE";
public static final String LEFT_SIDE_IMAGE_COLUMN = "LEFT_SIDE_IMAGE";
public static final String RIGHT_SIDE_IMAGE_COLUMN = "RIGHT_SIDE_IMAGE";
public static final String TAIL_IMAGE_COLUMN = "TAIL_IMAGE";
public static final String IDPROOF_IMAGE_COLUMN = "IDPROOF_IMAGE";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME_IMAGES + "(BANK_ID INTEGER PRIMARY KEY AUTOINCREMENT,BANK_NAME TEXT,INSURED_NAME TEXT,BANKHYPO_NAME TEXT,FARMER_NAME TEXT,VILLAGE TEXT,TALUKA TEXT,DISTRICT TEXT,TAGGING_DATE DATE, TAG NUMBER,ANIMAL_SPECIES TEXT,ANIMAL_BREED TEXT,ANIMAL_BODY_COLOR TEXT,ANIMAL_SHAPE_RIGHT TEXT,ANIMAL_SHAPE_LEFT TEXT,ANIMAL_SWITCH_OF_TAIL TEXT,AGE NUMBER,ANIMAL_OTHER_MARKS TEXT,PRAG_STATUS TEXT,NUMBER_OF_LACTATION NUMBER,CURRENT_MILK NUMBER,SUM_INSURED NUMBER,TAG_IMAGE BLOB NOT NULL,HEAD_IMAGE BLOB NOT NULL,LEFT_SIDE_IMAGE BLOB NOT NULL,RIGHT_SIDE_IMAGE BLOB NOT NULL,TAIL_IMAGE BLOB NOT NULL,IDPROOF_IMAGE BLOB NOT NULL)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_IMAGES);
onCreate(db);
}
public boolean insertImage(String bank, String insurename, String bankhypo, String farmername, String village, String taluka, String district, String tagging_date, String tag, String animal_species, String animal_breeds, String animal_body_color, String shape_right, String shape_left, String tail, String age, String marks_other, String prag, String lactation, String current_milk, String sum, byte[] tag_image, byte[] head_image, byte[] left_image, byte[] right_image, byte[] tail_image, byte[] id_proof_image) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(BANK_COLUMN, bank);
contentValues.put(INSURED_COLUMN, insurename);
contentValues.put(BNAKHYPO_COLUMN, bankhypo);
contentValues.put(FARMERNAME_COLUMN, farmername);
contentValues.put(VILLAGE_COLUMN, village);
contentValues.put(TALUKA_COLUMN, taluka);
contentValues.put(DISTRICT_COLUMN, district);
contentValues.put(TAGGING_DATE_COLUMN, tagging_date);
contentValues.put(TAG_COLUMN, tag);
contentValues.put(ANIMAL_SPECIES_COLUMN, animal_species);
contentValues.put(ANIMAL_BREED_COLUMN, animal_breeds);
contentValues.put(ANIMAL_BODY_COLOR_COLUMN, animal_body_color);
contentValues.put(ANIMAL_SHAPE_RIGHT_COLUMN, shape_right);
contentValues.put(ANIMAL_SHAPE_LEFT_COLUMN, shape_left);
contentValues.put(ANIMAL_SWITCH_OF_TAIL_COLUMN, tail);
contentValues.put(AGE_COLUMN, age);
contentValues.put(ANIMAL_OTHER_MARKS_COLUMN, marks_other);
contentValues.put(PRAG_STATUS_COLUMN, prag);
contentValues.put(NUMBER_OF_LACTATION_COLUMN, lactation);
contentValues.put(CURRENT_MILK_COLUMN, current_milk);
contentValues.put(SUM_INSURED_COLUMN, sum);
contentValues.put(TAG_IMAGE_COLUMN, tag_image);
contentValues.put(HEAD_IMAGE_COLUMN, head_image);
contentValues.put(LEFT_SIDE_IMAGE_COLUMN, left_image);
contentValues.put(RIGHT_SIDE_IMAGE_COLUMN, right_image);
contentValues.put(TAIL_IMAGE_COLUMN, tail_image);
contentValues.put(IDPROOF_IMAGE_COLUMN, id_proof_image);
long result = db.insert(TABLE_NAME_IMAGES, null, contentValues);
if (result == -1)
return false;
else
return true;
}
public DatabaseHelper open() throws SQLException {
SQLiteDatabase db = this.getWritableDatabase();
return this;
}
public List<DataModel> getdata() {
// DataModel dataModel = new DataModel();
List<DataModel> data = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select BANK_ID,BANK_NAME,INSURED_NAME,BANKHYPO_NAME,FARMER_NAME,VILLAGE,TALUKA,DISTRICT,TAGGING_DATE from " + TABLE_NAME_IMAGES + " ;", null);
StringBuffer stringBuffer = new StringBuffer();
DataModel dataModel = null;
while (cursor.moveToNext()) {
dataModel = new DataModel();
String BANK_ID = cursor.getString(cursor.getColumnIndexOrThrow("BANK_ID"));
String name = cursor.getString(cursor.getColumnIndexOrThrow("BANK_NAME"));
String country = cursor.getString(cursor.getColumnIndexOrThrow("INSURED_NAME"));
String city = cursor.getString(cursor.getColumnIndexOrThrow("BANKHYPO_NAME"));
String FARMER_NAME = cursor.getString(cursor.getColumnIndexOrThrow("FARMER_NAME"));
String VILLAGE = cursor.getString(cursor.getColumnIndexOrThrow("VILLAGE"));
String TALUKA = cursor.getString(cursor.getColumnIndexOrThrow("TALUKA"));
String DISTRICT = cursor.getString(cursor.getColumnIndexOrThrow("DISTRICT"));
String TAGGING_DATE = cursor.getString(cursor.getColumnIndexOrThrow("TAGGING_DATE"));
dataModel.setBANK_ID(BANK_ID);
dataModel.setId(name);
dataModel.setFarmer_insure_name(city);
dataModel.setFarmer_bank_hypo(country);
dataModel.setFarmer_name(FARMER_NAME);
dataModel.setVillage(VILLAGE);
dataModel.setTaluka(TALUKA);
dataModel.setDistrict(DISTRICT);
dataModel.setTagging_date(TAGGING_DATE);
stringBuffer.append(dataModel);
// stringBuffer.append(dataModel);
data.add(dataModel);
}
for (DataModel mo : data) {
Log.e("Hellomo", "" + mo.getFarmer_insure_name());
}
//
return data;
}
}
First Activity Class
public class SyncAllActivity extends AppCompatActivity {
Cursor model = null;
Cursor mode = null;
MyCustomAdapter adapter = null;
Button show;
DatabaseHelper database;
private RecyclerView recyclerview;
RecycleAdapter recycler;
List<DataModel> datamodel;
private ProgressDialog pdialog;
Context context;
private RecyclerView.LayoutManager mLayoutManager;
private MyCustomAdapter myCustomAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sync_all_activity);
context = this;
datamodel = new ArrayList<DataModel>();
recyclerview = findViewById(R.id.recycle);
database = new DatabaseHelper(SyncAllActivity.this);
datamodel = database.getdata();
recycler = new RecycleAdapter(datamodel);
Log.e("data", "" + datamodel);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerview.setLayoutManager(layoutManager);
recyclerview.setHasFixedSize(true);
myCustomAdapter = new MyCustomAdapter(datamodel);
recyclerview.setAdapter(myCustomAdapter);
}
public class MyCustomAdapter extends RecyclerView.Adapter<MyCustomAdapter.MyViewHolder> {
List<DataModel> moviesList;
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView bank_company, insured_name, bank_hypo;
CardView cardView;
MaterialRippleLayout next_button_main_activity;
public MyViewHolder(View view) {
super(view);
context = itemView.getContext();
bank_company = itemView.findViewById(R.id.tvInsuranceList);
insured_name = itemView.findViewById(R.id.tvInsuredName);
bank_hypo = itemView.findViewById(R.id.tvBankHypo);
cardView = itemView.findViewById(R.id.cardViewMain);
next_button_main_activity = itemView.findViewById(R.id.next_button_main_activity);
}
}
public MyCustomAdapter(List<DataModel> moviesList) {
this.moviesList = moviesList;
}
#Override
public MyCustomAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.sam1
, parent, false);
return new MyCustomAdapter.MyViewHolder(itemView);
}
public void clear() {
int size = this.moviesList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
this.moviesList.remove(0);
}
this.notifyItemRangeRemoved(0, size);
}
}
#Override
public void onBindViewHolder(final MyCustomAdapter.MyViewHolder holder, final int position) {
final DataModel dataModel = moviesList.get(position);
holder.bank_company.setText(dataModel.getId());
holder.insured_name.setText(dataModel.getFarmer_insure_name());
holder.bank_hypo.setText(dataModel.getFarmer_bank_hypo());
holder.cardView.setVisibility(View.VISIBLE);
holder.next_button_main_activity.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(context, SyncFarmerActivity.class);
intent.putExtra("BANK_ID", moviesList.get(position).getBANK_ID() + "");
Log.e("id", moviesList.get(position).getBANK_ID() + "");
startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return moviesList.size();
}
}
}
Second Activity Class
public class SyncFarmerActivity extends AppCompatActivity {
Button show;
DatabaseHelper database;
private RecyclerView recyclerview;
RecycleAdapter recycler;
List<DataModel> datamodel;
String id;
Context context;
private RecyclerView.LayoutManager mLayoutManager;
private MyCustomAdapter myCustomAdapter;
DataModel dataModel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sync_farmer);
context = this;
Intent i = getIntent();
id = i.getStringExtra("BANK_ID");
Log.e("BANK_ID", id + "");
datamodel = new ArrayList<DataModel>();
recyclerview = findViewById(R.id.recycle);
database = new DatabaseHelper(SyncFarmerActivity.this);
datamodel = database.getdata();
recycler = new RecycleAdapter(datamodel);
Log.e("HIteshdata", "" + datamodel);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerview.setLayoutManager(layoutManager);
recyclerview.setHasFixedSize(true);
myCustomAdapter = new MyCustomAdapter(datamodel);
recyclerview.setAdapter(myCustomAdapter);
}
public class MyCustomAdapter extends RecyclerView.Adapter<MyCustomAdapter.MyViewHolder> {
List<DataModel> moviesList;
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView tvFarmerName, tvCity, tvTaluka, farmer_name, tvDistrict, tvTaggingDate, district, tagging_date;
CardView cardView;
MaterialRippleLayout next_button_main_activity;
public MyViewHolder(View view) {
super(view);
context = itemView.getContext();
tvFarmerName = itemView.findViewById(R.id.tvFarmerName);
tvCity = itemView.findViewById(R.id.tvCity);
tvTaluka = itemView.findViewById(R.id.tvTaluka);
tvDistrict = itemView.findViewById(R.id.tvDistrict);
tvTaggingDate = itemView.findViewById(R.id.tvTaggingDate);
}
}
public MyCustomAdapter(List<DataModel> moviesList) {
this.moviesList = moviesList;
}
#Override
public MyCustomAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.sam
, parent, false);
return new MyCustomAdapter.MyViewHolder(itemView);
}
public void clear() {
int size = this.moviesList.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
this.moviesList.remove(0);
}
this.notifyItemRangeRemoved(0, size);
}
}
#Override
public void onBindViewHolder(MyCustomAdapter.MyViewHolder holder, final int position) {
DataModel dataModel = moviesList.get(position);
holder.tvFarmerName.setText(dataModel.getFarmer_name());
holder.tvCity.setText(dataModel.getVillage());
holder.tvTaluka.setText(dataModel.getTaluka());
holder.tvDistrict.setText(dataModel.getDistrict());
holder.tvTaggingDate.setText(dataModel.getTagging_date());
}
#Override
public int getItemCount() {
return moviesList.size();
}
}
}
Can anyone help me..
Thank You in advance.
You have to create another method in your Database class to select values from specific id that you are passing from first activity like:
DatabaseHelper Class
public List<DataModel> getSpecificData(String id) {
// DataModel dataModel = new DataModel();
List<DataModel> data = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select BANK_ID,BANK_NAME,INSURED_NAME,BANKHYPO_NAME,FARMER_NAME,VILLAGE,TALUKA,DISTRICT,TAGGING_DATE from " + TABLE_NAME_IMAGES + "WHERE BANK_ID = " + id + ";", null);
StringBuffer stringBuffer = new StringBuffer();
DataModel dataModel = null;
while (cursor.moveToNext()) {
//Rest of your code
return data;
}
And use this method in your second activity like
Intent i = getIntent();
id = i.getStringExtra("BANK_ID");
database = new DatabaseHelper(SyncFarmerActivity.this);
datamodel = database.getSpecificData(id);
friends...
In my project, I am creating a list of images from the server and showing in Recyclerview.
now I want to remove a particular item from the list when I click on the verify button.
I tried to hide holder.itemview but its see again when I scroll.
I just want to remove or hide that item which is verified once.
here is my code :
1) Main activity
public class MainActivity extends AppCompatActivity {
private static final String url = "www.mysite.com/api/api-id-list.php?action=imgs";
private ProgressDialog mDetailProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main_activity);
LoadRecyclerView();
}
private void LoadRecyclerView() {
mDetailProgress = new ProgressDialog(this);
mDetailProgress.setTitle("Loading images");
mDetailProgress.setMessage("Please Wait...");
mDetailProgress.setCanceledOnTouchOutside(false);
mDetailProgress.show();
final RecyclerView imgList = (RecyclerView) findViewById(R.id.imgList);
imgList.setLayoutManager(new LinearLayoutManager(this));
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
Image[] images = gson.fromJson(response, Image[].class);
imgList.setAdapter(new ImageAdapter(MainActivity.this, images));
mDetailProgress.dismiss();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getBaseContext(), "Something went wrong..!", Toast.LENGTH_LONG);
}
});
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(request);
}}
2) ImageAdapter
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private ProgressDialog mDetailProgress;
private Context context;
private Image[] data;
Button btn_ban, btn_verify;
private View view;
public ImageAdapter (Context context, Image[] data) {
this.context = context;
this.data = data;
}
#NonNull
#Override
public ImageViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int i) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.single_item, parent, false);
return new ImageViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ImageViewHolder holder, final int position) {
final Image imagelist = data[position];
holder.userCode.setText(imagelist.getCode());
Glide.with(holder.userImage.getContext()).load(imagelist.getIdPhoto()).into(holder.userImage);
btn_verify.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.itemView.setVisibility(View.GONE);
}
});
}
#Override
public int getItemCount() { return data.length; }
public class ImageViewHolder extends RecyclerView.ViewHolder {
TextView userCode;
ImageView userImage;
public ImageViewHolder(#NonNull View itemView) {
super(itemView);
userImage = (ImageView) itemView.findViewById(R.id.card_iv_img);
userCode = (TextView) itemView.findViewById(R.id.card_tv_code);
btn_ban = (Button) itemView.findViewById(R.id.btn_ban);
btn_verify = (Button) itemView.findViewById(R.id.btn_verify);
}
}}
3) Image.java
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Image {
#SerializedName("per_ID")
#Expose
private String perID;
#SerializedName("code")
#Expose
private String code;
#SerializedName("first_nm")
#Expose
private String firstNm;
#SerializedName("last_nm")
#Expose
private String lastNm;
#SerializedName("photo_ID")
#Expose
private String photoID;
#SerializedName("id_photo")
#Expose
private String idPhoto;
public String getPerID() {
return perID;
}
public void setPerID(String perID) {
this.perID = perID;
}
public Image withPerID(String perID) {
this.perID = perID;
return this;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Image withCode(String code) {
this.code = code;
return this;
}
public String getFirstNm() {
return firstNm;
}
public void setFirstNm(String firstNm) {
this.firstNm = firstNm;
}
public Image withFirstNm(String firstNm) {
this.firstNm = firstNm;
return this;
}
public String getLastNm() {
return lastNm;
}
public void setLastNm(String lastNm) {
this.lastNm = lastNm;
}
public Image withLastNm(String lastNm) {
this.lastNm = lastNm;
return this;
}
public String getPhotoID() {
return photoID;
}
public void setPhotoID(String photoID) {
this.photoID = photoID;
}
public Image withPhotoID(String photoID) {
this.photoID = photoID;
return this;
}
public String getIdPhoto() {
return idPhoto;
}
public void setIdPhoto(String idPhoto) {
this.idPhoto = idPhoto;
}
public Image withIdPhoto(String idPhoto) {
this.idPhoto = idPhoto;
return this;
}}
First make data not array, but List, so it's easy to remove item;
Secondly set listener for verify button inside ViewHolder and inside OnClick remove item and notify adapter.
btn_verify.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
data.remove(position);
notifyItemRemoved(position);
}
});
Note: Setting OnClickListener inside ViewHolder makes sure that only correct item is removed by using getAdapterPosition() to get correct position.
Position provided by onBindViewHolder might be invalid after new items are inserted.
Main activity.java
public class activity_3 extends AppCompatActivity {
TextView question,option_1,option_2,option_3,description,winnner;
NumberProgressBar option_progress1, option_progress2,option_progress3;
int val_1;
int val_2;
int val_3;
DatabaseReference Polldata_3;
String optionOne;
String optionTwo;
String optionThree;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);
final String que = getIntent().getExtras().getString("que");
final String des = getIntent().getExtras().getString("des");
optionOne = getIntent().getExtras().getString("option1");
optionTwo = getIntent().getExtras().getString("option2");
optionThree = getIntent().getExtras().getString("option3");
final String id_user = getIntent().getExtras().getString("id");
val_1 = getIntent().getExtras().getInt("val1");
val_2 = getIntent().getExtras().getInt("val2");
val_2 = getIntent().getExtras().getInt("val3");
option_progress1 = (NumberProgressBar) findViewById(R.id.option1_progressbar);
option_progress2 = (NumberProgressBar) findViewById(R.id.option2_progressbar);
option_progress3 = (NumberProgressBar) findViewById(R.id.option3_progressbar);
Polldata_3 = FirebaseDatabase.getInstance().getReference("POll").child("poll_3");
final DatabaseReference answsersave = Polldata_3.child(id_user);
question = (TextView) findViewById(R.id.question_showpoll);
option_1 = (TextView) findViewById(R.id.option_1);
option_2 = (TextView) findViewById(R.id.option_2);
option_3 = (TextView) findViewById(R.id.option_3);
description = (TextView) findViewById(R.id.description_user_3);
winnner = (TextView) findViewById(R.id.winner);
option_1.setText(optionOne);
option_2.setText(optionTwo);
option_3.setText(optionThree);
question.setText(que);
description.setText(des);
option_progress1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
option_progress1.setProgress(val_1+1);
option_progress1.setEnabled(false);
option_progress2.setEnabled(false);
option_progress3.setEnabled(false);
val_1++;
answsersave.child("option_1_value").setValue(val_1);
//winnerdeclare();
}
});
option_progress2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
option_progress2.setProgress(val_2+1);
option_progress1.setEnabled(false);
option_progress2.setEnabled(false);
option_progress3.setEnabled(false);
val_2++;
answsersave.child("option_2_value").setValue(val_2);
// winnerdeclare();
}
});
option_progress3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
option_progress3.setProgress(val_3+1);
option_progress1.setEnabled(false);
option_progress2.setEnabled(false);
option_progress3.setEnabled(false);
val_3++;
// winnerdeclare();
answsersave.child("option_3_value").setValue(val_3);
}
});
}
}
ADAPTER CLASS
public class listview_3 extends AppCompatActivity {
ListView listviewpoll3;
private DatabaseReference Poll_data_3;
List<addpoll_3> addpoll_3List;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview_3);
listviewpoll3 = (ListView) findViewById(R.id.poll_listview_3);
Poll_data_3 = FirebaseDatabase.getInstance().getReference("POll").child("poll_3");
addpoll_3List = new ArrayList<>();
listviewpoll3.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
Intent intent = new Intent(listview_3.this, activity_3.class);
addpoll_3 poll = addpoll_3List.get(position);
final String optionone = poll.getOption_1();
final String optiontwo = poll.getOption_2();
final String optionthree = poll.getOption_3();
final String id_user = poll.getId();
final int value_1 = poll.getOption_1_value();
final int value_2 = poll.getOption_2_value();
final int value_3 = poll.getOption_3_value();
final String question = poll.getQuestion();
final String desp = poll.getDescription();
intent.putExtra("option1",optionone);
intent.putExtra("option2",optiontwo);
intent.putExtra("option3",optionthree);
intent.putExtra("id",id_user);
intent.putExtra("val1",value_1);
intent.putExtra("val2",value_2);
intent.putExtra("val3",value_3);
intent.putExtra("que",question);
intent.putExtra("descp",desp);
startActivity(intent);
}
});
}
#Override
protected void onStart() {
super.onStart();
Poll_data_3.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
addpoll_3List.clear();
for(DataSnapshot pollSnapshot: dataSnapshot.getChildren())
{
addpoll_3 poll = pollSnapshot.getValue(addpoll_3.class);
addpoll_3List.add(poll);
}
poll_list_3 adapter = new poll_list_3(listview_3.this,addpoll_3List);
listviewpoll3.setAdapter(adapter);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
list class
public class poll_list_3 extends ArrayAdapter<addpoll_3> {
private Activity context;
private List<addpoll_3> addpoll_3List;
public poll_list_3(Activity context, List<addpoll_3> addpoll_3List) {
super(context, R.layout.list_layout, addpoll_3List);
this.context = context;
this.addpoll_3List = addpoll_3List;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View viewitem = inflater.inflate(R.layout.list_layout,null);
TextView textViewName = (TextView) viewitem.findViewById(R.id.tv);
TextView textViewDesp = (TextView) viewitem.findViewById(R.id.tv1);
final addpoll_3 poll1 = addpoll_3List.get(position);
textViewName.setText(poll1.getQuestion());
textViewDesp.setText(poll1.getDescription());
return viewitem;
}
}
I am making a polling app where user can create a poll which is then stored in the firebase database and retrieved into listview of the app
when the user clicks on the list view he is directed to the the activity where there are number of progressbars
i have added a ON-click listener o the progress bar, So when user clicks on the progressbar the val of that option gets incremented in the database. so when a different user vote on the same poll the value from the database is fetched and value of the current user is added displaying the winner,but problem is the value of the progressbar1 gets the value from the database but the other two keep progress bar values start from 0 every time user clicks on the other two progress bar (ie 2 and 3).
please help
addpoll_3.java
public class addpoll_3 {
String id;
String question;
String description;
String option_1;
String option_2;
String option_3;
int option_1_value;
int option_2_value;
int option_3_value;
public addpoll_3(){}
public addpoll_3(String id, String question, String description, String option_1, String option_2, String option_3, int option_1_value, int option_2_value, int option_3_value) {
this.id = id;
this.question = question;
this.description = description;
this.option_1 = option_1;
this.option_2 = option_2;
this.option_3 = option_3;
this.option_1_value = option_1_value;
this.option_2_value = option_2_value;
this.option_3_value = option_3_value;
}
public String getId() {
return id;
}
public String getQuestion() {
return question;
}
public String getDescription() {
return description;
}
public String getOption_1() {
return option_1;
}
public String getOption_2() {
return option_2;
}
public String getOption_3() {
return option_3;
}
public int getOption_1_value() {
return option_1_value;
}
public int getOption_2_value() {
return option_2_value;
}
public int getOption_3_value() {
return option_3_value;
}
}
code:
Activity_3.java
val_1 = getIntent().getExtras().getInt("val1");
val_2 = getIntent().getExtras().getInt("val2");
val_3 = getIntent().getExtras().getInt("val3");
These were changes to be made
//Read from the database
myRef.addValueEventListener(new ValueEventListener()
{
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
#Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
});
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
};