Reputation: 29
I would ask you a quick question.
In my layout, I have added a button with text "Go to store":
<Button
android:id="@+id/go_to_store"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to store"/>
I got the details from Json response:
JSONObject baseJsonResponse = new JSONObject(SAMPLE_JSON_RESPONSE);
JSONArray couponCategoryArray = baseJsonResponse.getJSONArray("results");
for (int i = 0; i < couponCategoryArray.length(); i++) {
JSONObject currentEarthquake = couponCategoryArray.getJSONObject(i);
JSONObject properties = currentEarthquake.getJSONObject("campaign");
String name = properties.getString("name");
String promo_code = currentEarthquake.getString("promocode");
String goto_store = currentEarthquake.getString("goto_link");
CouponCategory couponCategory = new CouponCategory(name, promo_code, goto_store);
couponcategory.add(couponCategory);
}
and
Button descriptionTextView = (Button) listItemView.findViewById(R.id.go_to_store);
descriptionTextView.setText(currentCouponCategory.getDescription());
descriptionTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(currentCouponCategory.getDescription()));
getContext().startActivity(browserIntent);
}
});
And the coupon Category is:
private String mStoreName;
private String mPromoCode;
private String mGotoStore;
public CouponCategory(String storeName, String promoCode, String gotoStore) {
mStoreName = storeName;
mPromoCode = promoCode;
mGotoStore = gotoStore;
}
//** Get the Magnitude of the earthquake*/
public String getStoreName() { return mStoreName; }
public String getPromoCode() { return mPromoCode; }
public String getDescription() { return mGotoStore; }}
JSON response:
\"image\":\"http://cdn.admitad.com/campaign/images/2015/03/13/26eb60d1e6b5d4ec7c92062e5d1e8430.jpg\",\n" +
" \"species\":\"promocode\",\n" +
" \"categories\":[\n" +
" {\n" +
" \"id\":8,\n" +
" \"name\":\"Компьютеры и электроника\"\n" +
" }\n" +
" ],\n" +
" \"name\":\"Banggood 10% OFF Site Wide Coupon\",\n" +
" \"promocode\":\"BGAFF10OFF\",\n" +
" \"frameset_link\":\"\",\n" +
" \"goto_link\":\"https://ad.admitad.com/g/tx4zgk4gbq2e4b3978f86213826a88/?i=3\"\n" +
I am trying to edit part of the code but I continue to see, in the button, the link of the store got from Json: https://ibb.co/ZTQkwH5
How could I fix it?
Thank you for your help.
Upvotes: 0
Views: 76
Reputation: 1986
Use this-->
descriptionTextView.setText("Go to store")
instead of -->
descriptionTextView.setText(currentCouponCategory.getStoreName());
Upvotes: 1