我有一个ListView,我有自己的自定义ListItem我正在对它们应用动作侦听器,但它们没有响应事件。
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);
}
});
}
答案 0 :(得分:3)
要注意的一件事是,当你创建吐司时,你不会显示它。
变化:
Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG);
到
Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG).show();
如果吐司仍未显示,请尝试从传递给View
的{{1}}获取上下文
onClick
答案 1 :(得分:0)
implements View.OnClickListener and override public void onClick(View v) { method
and all done