2

我的 ListView 有一个用于自定义 ArrayAdapter 的类,下面是代码。

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

看看这个context.startActivityForResult(intent, PICK_CONTACT); 我如何onActivityResult在我的 customArrayAdapter 中定义我的?

4

1 回答 1

0

onActivityResult(int requestCode, int resultCode, Intent data)是 Activity 类方法不适用于任何 JAVA 类。

它仅适用于 Android Activity 本身。

于 2013-02-03T05:09:01.897 回答