我有一个ListView填充其中每一行中的一项是NetworkImageView。现在,我将Intent putExtra()的每一行传递给detail_product活动。

使用TextViews,我正在做:

String pName = ((TextView) view.findViewById(R.id.name)).getText().toString();
...
i.putExtra(TAG_NAME, pName);


如何进行NetworkImageView?我不能使用getTextgetResources()

编辑

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (inflater == null)
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null)
        convertView = inflater.inflate(R.layout.list_row, null);

    if (imageLoader == null)
        imageLoader = AppController.getInstance().getImageLoader();
    NetworkImageView thumbNail = (NetworkImageView) convertView
            .findViewById(R.id.thumbnail);

    TextView name = (TextView) convertView.findViewById(R.id.name);


    Product m = productItems.get(position);

    // thumbnail image
    String url = m.getThumbnailUrl();
    thumbNail.setImageUrl(url, imageLoader);
    thumbNail.setTag(url);

    // name
    name.setText(m.getName());



}

最佳答案

没有可用于为NetworkImageView提供URL的吸气剂。

一种方法是为NetworkImageView使用标签。您可以将图像URL设置为NetworkImageView的标记。在Adapter for ListView的getView(...)内的holder.thumbNail.setTag(imgUrl)。

在您的ListView的onItemClick侦听器中

    listView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        NetworkImageView v = (NetworkImageView) view.findViewById(R.id.thumbnail);
        String imgUrl = (String) v.getTag();


另一种方法是通过反射[请避免使用,如您所见,我指的是“ mUrl”,它是NetworkImageView中使用的私有变量,很可能在任何时间点都发生变化]

    Class nw = NetworkImageView.class;
    try {
        Field url=nw.getDeclaredField("mUrl");
        url.setAccessible(true);
        String imgUrl=(String) url.get(your_networkview_object);
    } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }

10-05 17:42