2010-12-07 6 views
0

J'ai un ListView et j'ai mon propre ListItem personnalisé J'applique l'écouteur d'action sur eux mais ils ne répondent pas à l'événement.setOnClickListener ne fonctionne pas à l'intérieur de CustomAdapter extends ArrayAdapter

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); 
         } 
        }); 

       } 
+1

@Ajzaz: Pouvez-vous poster votre code complet dans pastebin.com –

+0

Thnx Shankar g :) –

Répondre

3

1 chose à noter est que lorsque vous créez votre pain grillé, vous ne vous présentez pas.

Change:

Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG); 

à

Toast.makeText(getContext(), "Accept", Toast.LENGTH_LONG).show(); 

Si le pain ne marche pas encore apparaître, essayez d'obtenir le contexte de la View qui est passé à onClick

Toast.makeText(arg0.getContext(), "Accept", Toast.LENGTH_LONG).show(); 
0
implements View.OnClickListener and override public void onClick(View v) { method 

and all done 
Questions connexes