I have an issue related to ListView, in this listview each row have own auction_id ,I want to use that auction_id when we click on the row and use auction_id in another Activity as a JSON input , please help me
here is my code
private void getMyAuctionList(JSONObject response){
//MyAuctionListBean listBean = new MyAuctionListBean();
List<MyAuctionListBean> list = new ArrayList<MyAuctionListBean>();
if(response != null){
try {
JSONArray jsonArray = response.getJSONArray("success");
for (int i = 0 ; i < jsonArray.length(); i++){
MyAuctionListBean listBean = new MyAuctionListBean();
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
listBean.setAuction_id(jsonObject1.getString("auction_id"));
listBean.setEvent_name(jsonObject1.getString("event_name"));
listBean.setContact_no(jsonObject1.getString("contact_no"));
listBean.setAuction_date(jsonObject1.getString("auction_date"));
listBean.setEnd_date(jsonObject1.getString("end_date"));
listBean.setLocation(jsonObject1.getString("location"));
listBean.setPeople_range(jsonObject1.getString("people_range"));
listBean.setPrice_range(jsonObject1.getString("price_range"));
listBean.setIs_active(jsonObject1.getString("is_active"));
listBean.setTotal_bid_count(jsonObject1.getString("total_bid_count"));
listBean.setTotal_quoted(jsonObject1.getString("total_quoted"));
listBean.setTAproved(jsonObject1.getString("TAproved"));
listBean.setAuction_description(jsonObject1.getString("auction_description"));
list.add(listBean);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
hAdapter = new MyAuctionHistoryAdapter(getActivity(),list);
hRecyclerView.setAdapter(hAdapter);
}
here is second Activity
private void getAuctionDetail(){
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
JSONObject jsonObject = null;
LoginBean loginBean = new LoginBean();
mSharedPreferences = getSharedPreferences("user_preference", Context.MODE_PRIVATE);
if(mSharedPreferences==null)
return;
String authorizationKey = mSharedPreferences.getString("authorization_key","");
String userId = mSharedPreferences.getString("userId", "");
//MyAuctionListBean listBean = new MyAuctionListBean();
try {
jsonObject = new JSONObject();
jsonObject.putOpt("authorization_key",authorizationKey);
jsonObject.putOpt("in_user_id",userId);
jsonObject.putOpt("device_token","1111");
jsonObject.putOpt("mac_address","1111");
jsonObject.putOpt("gps_latitude","1111");
jsonObject.putOpt("gps_longitude","1111");
jsonObject.putOpt("in_auction_id","");
} catch (JSONException e) {
e.printStackTrace();
}
CustomJSONObjectRequest jsonObjectRequest = new CustomJSONObjectRequest(Request.Method.POST, Constants.MYAUCTION_DETAIL_URL, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
getMyAuctionDetails(response);
Utility.showLogError(AuctionActivity.this, "GetAuctionDetailsResponse" + response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.hide();
}
});
Utility.showLogError(AuctionActivity.this, "Error in Detail"+"GetAuctionDetails URL = " + Constants.MYAUCTION_DETAIL_URL);
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
}
private void getMyAuctionDetails(JSONObject response) {
MyAuctionDetailsBean myAuctionDetailsBean = new MyAuctionDetailsBean();
if (response != null){
try {
JSONArray jsonArray = response.getJSONArray("success");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
myAuctionDetailsBean.setAuction_id(jsonObject.getString("auction_id"));
myAuctionDetailsBean.setContact_person(jsonObject.getString("contact_person"));
myAuctionDetailsBean.setPrimary_contact_no(jsonObject.getString("primary_contact_no"));
myAuctionDetailsBean.setAlternate_contact_no(jsonObject.getString("alternate_contact_no"));
myAuctionDetailsBean.setAuction_title(jsonObject.getString("auction_title"));
myAuctionDetailsBean.setClient_email(jsonObject.getString("client_email"));
myAuctionDetailsBean.setStart_date(jsonObject.getString("start_date"));
myAuctionDetailsBean.setEnd_date(jsonObject.getString("end_date"));
myAuctionDetailsBean.setLocation(jsonObject.getString("location"));
myAuctionDetailsBean.setPeople_range(jsonObject.getString("people_range"));
myAuctionDetailsBean.setPrice_range(jsonObject.getString("price_range"));
myAuctionDetailsBean.setFeatures_id(jsonObject.getString("features_id"));
myAuctionDetailsBean.setCuisine_id(jsonObject.getString("cuisine_id"));
myAuctionDetailsBean.setIs_active(jsonObject.getString("is_active"));
myAuctionDetailsBean.setTheme_id(jsonObject.getString("theme_id"));
myAuctionDetailsBean.setEvent_type_id(jsonObject.getString("event_type_id"));
myAuctionDetailsBean.setTotal_bid_count(jsonObject.getString("total_bid_count"));
myAuctionDetailsBean.setTotal_quoted(jsonObject.getString("total_quoted"));
myAuctionDetailsBean.setTAproved(jsonObject.getString("TAproved"));
myAuctionDetailsBean.setAuction_description(jsonObject.getString("auction_description"));
myAuctionDetailsBean.setEvent_name(jsonObject.getString("event_name"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
partyType.setText(myAuctionDetailsBean.getEvent_name());
location.setText(myAuctionDetailsBean.getLocation());
date.setText(myAuctionDetailsBean.getStart_date());
time.setText(myAuctionDetailsBean.getEnd_date());
theme.setText(myAuctionDetailsBean.getTheme_id());
noOfPeople.setText(myAuctionDetailsBean.getPeople_range());
mobileNo.setText(myAuctionDetailsBean.getPrimary_contact_no());
emailId.setText(myAuctionDetailsBean.getClient_email());
cuisine.setText(myAuctionDetailsBean.getCuisine_id());
requirment.setText(myAuctionDetailsBean.getAuction_description());
budget.setText(myAuctionDetailsBean.getPrice_range());
postUser.setText(myAuctionDetailsBean.getContact_person());
}
public void onBackPressed() {
finish();
}
public class MyAuctionHistoryAdapter extends RecyclerView.Adapter<MyAuctionHistoryAdapter.ViewHolder> {
private List<MyAuctionListBean> list;
private Context hContext;
private ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public MyAuctionHistoryAdapter(Context hContext,List<MyAuctionListBean> list){
this.hContext = hContext;
this.list = list;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.auction_history_row,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.partyType.setText(list.get(position).getEvent_name());
holder.partyLocation.setText(list.get(position).getLocation());
holder.date.setText(list.get(position).getAuction_date());
holder.bidCount.setText(list.get(position).getTotal_bid_count());
holder.priceRange.setText(list.get(position).getPrice_range());
holder.auctionDetailRowLay.setId(Integer.parseInt(list.get(position).getAuction_id()));
holder.rowAuction_Id.setText(list.get(position).getAuction_id());
}
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView partyType,partyLocation,restroType,budget,requirments,date,priceRange,bidCount;
private RelativeLayout auctionDetailRowLay;
private ImageView restoIcon;
TextView rowAuction_Id;
public ViewHolder(View view) {
super(view);
view.setOnClickListener(this);
partyType = (TextView)view.findViewById(R.id.H_auctionPartyType);
partyLocation = (TextView)view.findViewById(R.id.H_auctionLocation);
restroType = (TextView)view.findViewById(R.id.restro_Name);
budget = (TextView)view.findViewById(R.id.H_auction_Budget);
requirments = (TextView)view.findViewById(R.id.H_auctionRequirments);
date = (TextView)view.findViewById(R.id.H_auctionDate);
bidCount = (TextView)view.findViewById(R.id.H_auction_Bids);
priceRange = (TextView)view.findViewById(R.id.H_auction_RangeList);
auctionDetailRowLay= (RelativeLayout)view.findViewById(R.id.auctionDetailRow);
rowAuction_Id = (TextView)view.findViewById(R.id.row_Auction_id);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(hContext, AuctionActivity.class);
hContext.startActivity(intent);
}
}
}