Reputation: 21899
I have a ListView and I have my own customized ListItem I am applying action listener on them but they are not responding to event.
private class CustomAdapter extends ArrayAdapter<FriendInfo> {
public CustomAdapter (Context context, int textViewResourceId,
ArrayList<FriendInfo> friendList) {
super(context, textViewResourceId, friendList);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
try {
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.friend_item, null);
}
if(isViewInvitations){
Button btn_AcceptFrndReq = (Button)v.findViewById(R.id.btnAcceptFrndReq);
Button btn_DelFrnd = (Button)v.findViewById(R.id.btnDelFrnd);
btn_DelFrnd.setClickable(true);
btn_AcceptFrndReq.setVisibility(View.VISIBLE);
btn_DelFrnd.setVisibility(View.VISIBLE);
btn_AcceptFrndReq.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG);
}
});
btn_DelFrnd.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
//do delete call here in new thread
Toast.makeText(context, "Delete", Toast.LENGTH_LONG);
}
});
}
Upvotes: 0
Views: 2293
Reputation: 49410
1 thing to notice is that when you create your toast, you don't show it.
Change:
Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG);
to
Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG).show();
If the toast still doesnt show up, try getting the context from the View
that is passed to onClick
Toast.makeText(arg0.getContext(), "Accept", Toast.LENGTH_LONG).show();
Upvotes: 2
Reputation: 21899
implements View.OnClickListener and override public void onClick(View v) { method
and all done
Upvotes: 0