2

I have a class for custom ArrayAdapter for my ListView, below is the code.

public class CustomArrayAdapterForProduct extends ArrayAdapter<ProductClass> 
{
    private final Activity context;
    public final ArrayList<ProductClass> products;
    private static final int PICK_CONTACT = 1;

    public CustomArrayAdapterForProduct(Activity context, ArrayList<ProductClass> products) 
    {
        super(context, R.layout.product, products);
        this.context = context;
        this.products = products;
    }

    static class ViewHolder {
        protected TextView name;
        protected Button share;
        protected Button call;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {       
            View view = null;
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.product, parent,false);
            final ViewHolder viewHolder = new ViewHolder();
            final ProductClass file =   products.get(position);

            viewHolder.name = (TextView) view.findViewById(R.id.name);
            viewHolder.share = (Button) view.findViewById(R.id.videoView);
            viewHolder.call = (Button) view.findViewById(R.id.videoView);



            viewHolder.share.setOnClickListener(new OnClickListener() 
            {
                public void onClick(View v) 
                {
                  Intent intent = new Intent(Intent.ACTION_PICK,  Contacts.CONTENT_URI);
                  context.startActivityForResult(intent, PICK_CONTACT);
                }

            });


            viewHolder.name.setText(file.name.toString());
            view.setTag(viewHolder);

        return view;
    }
}

Look at this context.startActivityForResult(intent, PICK_CONTACT); how can i define my onActivityResult in my customArrayAdapter?

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

0

onActivityResult(int requestCode, int resultCode, Intent data) is Activity class method not for any JAVA class.

Its only works for Android Activity itself.

Dixit Patel
  • 3,190
  • 1
  • 24
  • 36
  • either you have to put CustomArrayAdapterForProduct in Your Activity Class or use Interface. – Dixit Patel Feb 03 '13 at 05:20
  • This doesn't solve the problem, only states it. It is logical to assign button click events in a custom ArrayAdapter, and sometimes those button clicks call activities, whether it be a full "page" or an activity acting as a dialog. Defining and implementing an interface doesn't necessarily mean that the framework will call the onActivityResult method at the proper time. – David R. Aug 04 '14 at 21:13