Reputation: 335
I created a voteUp method as follows,
public class Voting {
public void onUpVote(View view) {
CharSequence VoteUpId = ((TextView) ((RelativeLayout) view.getParent()).getChildAt(1)).getText();
final RequestQueue mrequestQueue = VolleySingleton.getInstance().getRequestQueue();
final String PUT_VOTE_UP = "URL + VoteUpId + URL";
StringRequest PostVoteUp = new StringRequest(Request.Method.PUT, PUT_VOTE_UP, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response + "reponse");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
System.out.println("************Answer" + error + "error");
}
});
mrequestQueue.add(PostVoteUp);
}
This method takes a view object, and I also have another method as shown below in another class where I set an onClickListner
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
VoteClass(What Do I pass In here??);
}
});
And I want to pass in a child of the view that is different from the button view from the same layout, and no I do not want to use the direct onClick from the xml layout to the class. So how do i do this?
Upvotes: 0
Views: 532
Reputation: 4910
implement the View.OnClickListener class and pass the view as argument like this
class CustomClickListener implements View.OnClickListener{
View view;
public CustomClickListener(View view){
this.view = view;
}
@Override
public void onClick(View v) {
VoteClass(view);
}
}
and then
mButton.setOnClickListener(new CustomClickListener(the view you want to pass));
Upvotes: 1