Refer the image
I want to match elements of favourite_city with options and if match found set favourite_city list as topmost position in options with its own content.
First ArrayList:
favourite_city=["Hyderabad","Bangalore"]
Second ArrayList:
options=["Nashik","Hyderabad","Mumbai","Bangalore","Chennai","Pune"]
Result:
options=["Hyderabad","Bangalore","Nashik","Hyderabad","Mumbai","Bangalore","Chennai","Pune"]
DocumentReference docRef5 = FirebaseFirestore.getInstance().collection("admin").document("users_profile").collection("dynamic_profile").document("city");
docRef5.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
#Override
public void onComplete(#NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null) {
//-----------code for loading array item from firebase to spinner view-----------------
final List<String> group = (List<String>) document.get("favourite_city");
Log.d(TAG, "favourite city list data: " + group);
final List<String> group1 = (List<String>) document.get("options");
Log.d(TAG, "options list data: " + group1);
cityAdapter = new ArrayAdapter<String>(AdminSetting.this, android.R.layout.simple_spinner_item, group1);
cityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
citySpinner.setAdapter(cityAdapter);
StringBuilder str = new StringBuilder();
for (int i = 0; i < group.size(); i++) {
if (i >= 0)
str = str.append(group.get(i));
String searchedItem = str.toString();
Log.d(TAG, "result " + searchedItem);
int itemPosition = cityAdapter.getPosition(searchedItem);
for(int j=0;j<=i;j++) {
if (itemPosition == -1) {
String message = searchedItem + " : Item not found.";
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
} else {
String message = searchedItem + " : Item found and selected.";
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
citySpinner.setSelection(itemPosition);
}
}
Log.d(TAG, "after appending " + str);
}
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
In order to put in the first positions the favourites cities, you need to know if they are contained in the cities list.
Check this code as an example:
ArrayList<String> favourites = new ArrayList<>(Arrays.asList("city1", "city2"));
ArrayList<String> cities = new ArrayList<>(Arrays.asList("city3", "city4", "city1", "city2"));
for (String favCity : favourites) {
if (cities.contains(favCity)) {
cities.add(favourites.indexOf(favCity), favCity);
}
}
System.out.println(cities);
This will print the following:
[city1, city2, city3, city4, city1, city2]
If you want to remove the duplicated favourites cities to keep only them in the first positions, you should add this line before adding it to the list.
cities.remove(favCity);
And it will return:
[city1, city2, city3, city4]
First of all your question is not clear
If you want to merge two arraylist you need to use below code
favourite_city.addAll(options) // or Either way
If you want to find matches some you need to do like below
public String getUserId(ArrayList<User> newUsers, ArrayList<User> oldUsers, String email) {
String userId = null;
for (User user1 : newUsers) {
if (user1.email.equals(email)) {
userId = user1.uid;
break;
}
}
if(userId == null){
for (User user2 : oldUsers) {
if (user2.email.equals(email)) {
userId = user2.uid;
break;
}
}
}
return userId;
}
Related
i want to make app With Rest Api and Retrofit. i want to load Random posts when user pull down the RecyclerView, i made it but one thing that is annoying, when i load Random posts. it display after the first 10 posts, i mean after home page's 10 posts but i want to clear the old posts and display random posts from row 1.
the code i am using for scroll up
else if (!recyclerView.canScrollVertically(-1) && dy < 0)
{
yourURL1 = baseURL + baseModel + "&orderby=rand&page=" + pageNo++;
getRetrofit1();
}
Retrofit
try {
List<Model> list = new ArrayList<>();
Call<List<WPPost>> call = service.getPostInfo( yourURL);
call.enqueue(new Callback<List<WPPost>>() {
#Override
public void onResponse(Call<List<WPPost>> call, Response<List<WPPost>> response) {
Log.d("==>>", " response "+ response.body());
mListPost = response.body();
progressBar.setVisibility(View.GONE);
if (response.body() != null) {
for (int i = 0; i < response.body().size(); i++ ) {
Log.d("==>>", " title " + response.body().get(i).getTitle().getRendered() + " " +
response.body().get(i).getId());
String tempdetails = String.valueOf((Html.fromHtml(response.body().get(i).getExcerpt().getRendered().toString())));
tempdetails = tempdetails.replace("<p>", "");
tempdetails = tempdetails.replace("</p>", "");
tempdetails = tempdetails.replace("[…]", "");
list.add(new Model(String.valueOf((Html.fromHtml(response.body().get(i).getTitle().getRendered()))),
tempdetails, response.body().get(i).getPostViews().toString(),
response.body().get(i).getImages().getMedium(),response.body().get(i).getContent().getRendered()));
}
if (loading){
loading = false;
adapter.showHideProgress(false);
}
adapter.addItemsToList(list);
progressBar.setVisibility(View.GONE);
} else {
progressBar.setVisibility(View.GONE);
}
}
#Override
public void onFailure(Call<List<WPPost>> call, Throwable t) {
}
});
}catch (Exception exception){
Log.d("tisha==>>"," "+exception.getLocalizedMessage());
}
In adapter
void addItemsToList(List<Model> newItems){
if (dataset.isEmpty()){
dataset.addAll(newItems);
notifyDataSetChanged();
Log.d("tisha==>>","First time List size = "+dataset.size());
}else {
int lastItemPosition = dataset.size() -1;
Log.d("tisha==>>","Old list size = "+dataset.size()+ "Last Item position= "+lastItemPosition);
dataset.addAll(newItems);
Log.d("tisha==>>","Update List size = "+dataset.size());
notifyItemRangeInserted(lastItemPosition,newItems.size());
}
}
how can i clear list ?
once this list is set you are adding items to list , you have to remove elements first notify item ranged removed then add new and update on notify item inserted
void addItemsToList(List<Model> newItems)
{ if (dataset.isEmpty())
{ dataset.addAll(newItems);
notifyDataSetChanged();
Log.d("tisha==>>","First time List size = "+dataset.size());
}
else
{
int lastItemPosition = dataset.size() -1;
Log.d("tisha==>>","Old list size = "+dataset.size()+ "Last Item position= "+lastItemPosition); dataset.addAll(newItems);
Log.d("tisha==>>","Update List size = "+dataset.size()); notifyItemRangeInserted(lastItemPosition,newItems.size()); } }
I'm having a problem updating data from SQLite when API response are success, for example, I have 5 pending data, My codes are getting and sending data from database. but only the last data had update in SQLite. I have logged ticket_tick_no_delayedinside onResponse and this is what I've get. any insights?.
Please take a look at my code:
private void checkingUnsendData() {
String query = ("select * from tickets where is_send = '2' or is_send = '0' ");
Cursor c = sqldb.rawQuery(query, null);
if (c != null && c.moveToFirst()) {
while (!c.isAfterLast()) {
trip_no_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_TRIP_NO));
ticket_control_no_delayed = c.getString(c.getColumnIndex(DBHelper.CONTROL_NO));
ticket_tick_no_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_NO));
ticket_datetime_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DATETIME));
ticket_kmfrom_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_KMFROM));
ticket_kmto_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_KMTO));
ticket_placefrom_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_PLACEFROM));
ticket_placeto_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_PLACETO));
ticket_amount_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_AMOUNT));
ticket_discount_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DISCOUNT));
transaction_type_delayed = c.getString(c.getColumnIndex(DBHelper.TRANSACTION_TYPE));
passenger_type_delayed = c.getString(c.getColumnIndex(DBHelper.PASSENGER_TYPE));
ticket_lat_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_LAT));
ticket_long_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_LONG));
device_serial_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DEVICE_SERIAL));
sendUnsendData();
c.moveToNext();
}
}
c.close();
}
private void sendUnsendData() {
JSONObject params = new JSONObject();
try {
params.put("control_no", ticket_control_no_delayed);
params.put("trip_no", trip_no_delayed);
params.put("ticket_no", ticket_tick_no_delayed);
params.put("ticket_datetime", ticket_datetime_delayed);
params.put("ticket_kmfrom", ticket_kmfrom_delayed);
params.put("ticket_kmto", ticket_kmto_delayed);
params.put("ticket_placefrom", ticket_placefrom_delayed);
params.put("ticket_placeto", ticket_placeto_delayed);
params.put("amount", ticket_amount_delayed);
params.put("discount", ticket_discount_delayed);
params.put("trans_type", transaction_type_delayed);
params.put("passenger_type", passenger_type_delayed);
params.put("lat", ticket_lat_delayed);
params.put("long", ticket_long_delayed);
params.put("device_serial", device_serial_delayed);
AndroidNetworking.post("MY_LINK.COM")
.addJSONObjectBody(params)
.addHeaders("Content-Type", "application/json")
.addHeaders("Prefer", "return=representation")
.setPriority(Priority.HIGH)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
#Override
public void onResponse(JSONArray response) {
String qu = ("update tickets set is_send = '1' where ticket_tick_no = '" + ticket_tick_no_delayed + "'");
sqldb.execSQL(qu);
Log.e("ticket_tick_no_delayed", ticket_tick_no_delayed);
}
#Override
public void onError(ANError error) {
// handle error
asd(error);
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
EDIT
I've put log after the params.put... and I'm getting the data successfully.
see the image below:
I have resolved it by using List<String> array = new ArrayList<>();.
When I'm passing the data from SQLite, I put array.add(); inside the looping.
this is the code:
`while (!c.isAfterLast()) {
trip_no_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_TRIP_NO));
ticket_control_no_delayed = c.getString(c.getColumnIndex(DBHelper.CONTROL_NO));
ticket_tick_no_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_NO));
ticket_datetime_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DATETIME));
ticket_kmfrom_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_KMFROM));
ticket_kmto_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_KMTO));
ticket_placefrom_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_PLACEFROM));
ticket_placeto_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_PLACETO));
ticket_amount_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_AMOUNT));
ticket_discount_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DISCOUNT));
transaction_type_delayed = c.getString(c.getColumnIndex(DBHelper.TRANSACTION_TYPE));
passenger_type_delayed = c.getString(c.getColumnIndex(DBHelper.PASSENGER_TYPE));
ticket_lat_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_LAT));
ticket_long_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_LONG));
device_serial_delayed = c.getString(c.getColumnIndex(DBHelper.TICKET_DEVICE_SERIAL));
array.add(ticket_tick_no_delayed); // additional code
sendUnsendData();
c.moveToNext();
}`
After getting all the data, If the Response from AndroidNetworking has succeed, I put for each loop on OnResponse and using the List that I've used.
Take a look at it:
for (String value: array) {
String qu = ("update tickets set is_send = '1' where ticket_tick_no = '" + value + "'");
sqldb.execSQL(qu);
}
I need some help with Realm.
I have a Realm object: PokemonExperience with RealmList<RealmString>
public class PokemonExperience extends RealmObject {
public RealmList<RealmString> mainSkills;
public RealmList<RealmString> getMainSkills() {
return mainSkills;
}
public void setMainSkills(RealmList<RealmString> mainSkills) {
this.mainSkills = mainSkills;
}
And I have my RealmString object as well, with only value field.
With this, I have a multiple choice list with checkboxes, and these checkboxes have onClickListeners. When I check the boxes, I would like to save all the values into my RealmString model, and then save the RealmStrings into the RealmList<RealmString> in my PokemonExperience model.
Here's my code to do that:
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
//inflate Layout
convertView = layoutInflater.inflate(R.layout.fragment_multiple_choice_adapter, parent, false);
convertView.findViewById(R.id.fragment_multiple_choice_checkbox);
viewHolder.checkBox.setOnClickListener(view -> {
setCheckListener(viewHolder);
});
convertView.setTag(viewHolder);
if (selectedPositions.size() == 0) {
Method getter = getGetter(field);
try {
List<Object> values = Arrays.asList(data.values().toArray());
Object result = getter.invoke(object);
List<Object> resultAsList = (List<Object>) result;
for (int i = 0; i < values.size(); i++) {
if (resultAsList.contains(values.get(i))) {
selectedPositions.add(i);
}
viewHolder.checkBox.setChecked(position == selectedPositions.get(i));
viewHolder.position = position;
}
} catch (Exception e) {}
}
List<Object> keys = Arrays.asList(data.keySet().toArray());
viewHolder.textView.setText(keys.get(position).toString());
viewHolder.position = position;
return convertView;
}
private Method getSetter(Field field) {
return settersMap.get(field);
}
private Method getGetter(Field field) {
return gettersMap.get(field);
}
private boolean isGetter(Method method) {
return method.getName().startsWith("get") &&
method.getParameterTypes().length == 0 &&
!void.class.equals(method.getReturnType());
}
private boolean isSetter(Method method) {
return method.getName().startsWith("set") &&
method.getParameterTypes().length == 1;
}
private String croppedMethodName(boolean isGetter, boolean isSetter, Method method) {
if (!isGetter && !isSetter) {
return null;
}
if (isSetter &&
method.getParameterTypes()[0].getName().equals(boolean.class.getCanonicalName())) {
char[] c = new StringBuilder(method.getName()).substring(2).toCharArray();
c[0] = Character.toLowerCase(c[0]);
return new String(c);
}
char[] c = new StringBuilder(method.getName()).substring(3).toCharArray();
c[0] = Character.toLowerCase(c[0]);
return new String(c);
}
private void setCheckListener(ViewHolder viewHolder) {
selectedPosition = viewHolder.position;
Log.d(TAG, "getView: 111: " + selectedPosition);
// We save our values here to Realm
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
Method setter = getSetter(field);
try {
List<Object> values = Arrays.asList(data.values().toArray());
// taking a piece of string based on viewHolder.position to determine
// what is the "object" we should be saving
Object selectedObject = values.get(viewHolder.position);
Log.d(TAG, "selectedObject: " + selectedObject);
RealmString selectedRealmString = (RealmString) selectedObject;
Log.d(TAG, "realmString: " + selectedRealmString);
String selectedRealmStringValue = selectedRealmString.getValue();
Log.d(TAG, "realmStringValue: " + selectedRealmStringValue);
RealmResults<RealmString> realmStrings = realm.where(RealmString.class).findAll();
if (!realmStrings.contains(selectedRealmStringValue)) {
selectedRealmString = new RealmString();
selectedRealmString.setValue(selectedRealmStringValue);
realm.copyToRealm(selectedRealmString);
}
Log.d(TAG, "saved realmString: " + selectedRealmString);
Log.d(TAG, "saved realmStringValue: " + selectedRealmStringValue);
Log.d(TAG, "RealmResult size: " + realmStrings.size());
Log.d(TAG, "RealmResult: " + realmStrings.toArray().toString());
Method getter = getGetter(field);
Log.d(TAG, "getter name: " + getter.getName());
Object existingObjects = getter.invoke(object);
Log.d(TAG, "existingObjects: " + existingObjects);
RealmList<RealmString> existingValues;
existingValues = (RealmList<RealmString>) existingObjects;
Log.d(TAG, "existingValues1: " + existingValues);
if (!existingValues.contains(selectedRealmString)) {
Log.d(TAG, "existingValues2: " + existingValues);
existingValues.add(selectedRealmString);
}
Log.d(TAG, "existingValues3: " + existingValues);
setter.invoke(object, existingValues);
Log.d(TAG, "setCheckListener: setter is: " + setter.getName());
} catch (Exception e) {
e.printStackTrace();
}
realm.commitTransaction();
realm.close();
viewHolder.checkBox.setChecked(true);
notifyDataSetChanged();
}
My questions:
Why are my values saved to My RealmString model twice? Whenever I click on any checkbox, the String value of that checkbox gets saved twice.
Why are the values saved to the RealmString model even though there is a check for that.
if (!realmStrings.contains(selectedRealmStringValue)) {
//...
}
This is supposed to ensure that only new values are saved.
The RealmList<RealmString> does not get saved to my PokemonExperience's mainSkills field.
Any help is appreciated. Thanks a lot!
selectedRealmString is an unmanaged object, and you are inserting into your Realm twice (realm.copyToRealm(selectedRealmString) and existingValues.add(selectedRealmString)). You could do selectedRealmStringManaged = realm.copyToRealm(selectedRealmString) and later do existingValues.add(selectedRealmStringManaged).
I think you should check like that
if (!realmStrings.contains(selectedRealmString)) {
...
}
because selectedRealmString is instance of RealmString class, selectedRealmStringValue is instance of String class and your RealmResults contains RealmString
if (!realmStrings.contains(selectedRealmString)) {
...
}
The above doesn't work because what we really need to do is to compare the value of the objects.
This works:
ArrayList<String> existingValuesArrayList = new ArrayList<>();
for (int i = 0; i < existingValues.size(); i++) {
existingValuesArrayList.add(existingValues.get(i).getValue());
}
if (!existingValuesArrayList.contains(selectedRealmString.getValue())) {
//...
}
public void displayItems(View view) {
String s2 = editText.getText().toString();
ArrayList<HashMap<String, String>> allItems = dbcontroller.searchdata(s2);
ArrayList<HashMap<String, String>> a = dbcontroller.getcbrands();
String firstCompany="",secondCompany="";
long count = 0;
long ean_num = Long.parseLong(s2);
if (allItems.size() == 0) {
allItems = dbcontroller.getpdata(s2);
for (HashMap<String, String> map : allItems) {
//if (map.get("EAN").equals(s2)) {
//pselected.add(map);
//if (map.get("EAN")..equals(s2)) {
long ean_num_pred = Long.parseLong(map.get("EAN"));
Log.d("coredictor", "the value is " + ean_num);
Log.d("coredictor", "the predicted value is " + ean_num_pred);
count = count + 1;
if (count == 1) {
firstCompany = map.get("COMPANY");
selected.add(map);
}
if (count == 2) {
secondCompany = map.get("COMPANY");
}
}
long belowRange = ean_num - 50;
long aboveRange = ean_num + 50;
Log.d("coredictor", "the Input is " + ean_num);
// Log.d("coredictor", "the Ma{ean} is" + ean_num_pred);
// Log.d("coredictor", "the Below Value is " + belowRange);
// Log.d("coredictor", "the Abouve Value is " + aboveRange);
if (firstCompany!=secondCompany) {
//selected = pselected;
// String =dbcontroller.insertReport(editText.getText().toString());
boolean isInserted = dbcontroller.insertReport(editText.getText().toString(),"5");
//dbcontroller.insertReport("5");
if (isInserted = true)
Toast.makeText(Search.this, "Data inserted", Toast.LENGTH_LONG).show();
else
Toast.makeText(Search.this, "Data not inserted", Toast.LENGTH_LONG).show();
selected = pselected;
textView.setText("ITEM UNKNOWN");
selected.clear();
textView.setTextColor(Color.RED);
} else {
boolean isInserted = dbcontroller.insertReport(editText.getText().toString(),"4");
if (isInserted = true)
Toast.makeText(Search.this, "Data inserted", Toast.LENGTH_LONG).show();
else
Toast.makeText(Search.this, "Data not inserted", Toast.LENGTH_LONG).show();
selected = pselected;
textView.setText("ITEM PREDICTED");
editText.setText("");
textView.setTextColor(Color.GREEN);
}
} else {
for (HashMap<String, String> map : allItems) {
if (map.get("EAN").equals(s2)) {
boolean isInserted = dbcontroller.insertReport(editText.getText().toString(),"1");
if (isInserted = true)
Toast.makeText(Search.this, "Data inserted", Toast.LENGTH_LONG).show();
else
Toast.makeText(Search.this, "Data not inserted", Toast.LENGTH_LONG).show();
selected.add(map);
textView.setText("ITEM FOUND!!!!!");
textView.setTextColor(Color.BLUE);
editText.setText("");
}
ListAdapter adapter = new SimpleAdapter(Search.this, selected,R.layout.displays_searchitems, new String[]{"EAN","COMPANY", "NAME","DESCRIPTION", "BRAND", "CBRAND"}, new int[]{
R.id.ets_ean, R.id.ets_company, R.id.ets_name, R.id.ets_desc, R.id.ets_brand, R.id.ets_cbrands});
customList.setAdapter(adapter);
So this my adapter. Search is the name of my class. R.id.ets_ean, R.id.ets_company,.... are all the id of the editText that i'm displaying the data into from the database.
The problem is, each time i search for new result it's displaying one below the other than auto-refreshing.
notifyDataSetChanged() is not working.
I have retrieve data from json and set in onbind in recycle list view like
how can add value in spinner product.setQuantity(quantity); for each row
private ArrayList<ProductBySubCategory> parseJSONResponse(JSONArray response) {
ArrayList<ProductBySubCategory> listProducts = new ArrayList<ProductBySubCategory>();
if (response != null && response.length() > 0) {
try {
StringBuilder data = new StringBuilder();
JSONArray jsonArray = response;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pName = jsonObject.getString(KEY_NAME);
String pPrice = jsonObject.getString(KEY_PRICE);
String pUrlThumbnail = AppConfig.URL_THUBMNAIL_BASE + jsonObject.getString(KEY_THUMBNAIL);
String pSNo = jsonObject.getString(KEY_SNO);
String sellerName = jsonObject.getString(KEY_SELLER_NAME);
String qrValue = jsonObject.getString(KEY_QRVALUE);
String quantity = jsonObject.getString(KEY_QUANTITY);
data.append(pName + " " + pPrice + " " + pUrlThumbnail + " " + pSNo + " " + sellerName +" "+qrValue+ " "+quantity+ "\n");
ProductBySubCategory product = new ProductBySubCategory();
product.setpName(pName);
product.setSellerName(sellerName);
product.setQrValue(qrValue);
product.setpPrice(getString(R.string.material_icon_rupees)+pPrice);
product.setpUrlThumbnail(pUrlThumbnail);
product.setpSNo(pSNo);
product.setQuantity(quantity);
listProducts.add(product);
}
Log.d("Lifecycle2", listProducts.toString());
} catch (JSONException e) {
Log.d("Lifecycle", "Inside JSON EXCEPTION: " + e);
}
}
return listProducts;
}
In above code i want to quantity in spinner for each row.
I have set value in adapter in below code but I didn't set quantity in text view because I want to this value set in spinner and I have array value for spinner for each product in list and now what should I do for set value in spinner like this image for each item if possible please give me some code.
#Override
public void onBindViewHolder(final ViewHolderProducts holder, int position) {
ProductBySubCategory currentProduct = productArrayList.get(position);
holder.productName.setText(currentProduct.getpName());
holder.sellerName.setText(currentProduct.getSellerName());
holder.qrValue.setText(currentProduct.getQrValue());
holder.productPrice.setText(currentProduct.getpPrice());
holder.btnBuy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
RelativeLayout relativeLayout = (RelativeLayout) view.getParent();
TextView textView = (TextView) relativeLayout.findViewById(R.id.qrValue);
String qrText = (String) textView.getText();
Log.d("Abhinav", "qrValue" +qrText);
if (buyItemClickListener != null) {
buyItemClickListener.buttonClicked(qrText);
}
}
});
String urlThumbnail = currentProduct.getpUrlThumbnail();
if (urlThumbnail != null) {
imageLoader.get(urlThumbnail, new ImageLoader.ImageListener() {
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean b) {
holder.productThumbnail.setImageBitmap(response.getBitmap());
}
#Override
public void onErrorResponse(VolleyError volleyError) {
}
});
}
}