java-来自适配器的访问片段

这个想法是我有一个列表视图,其中每个项目都是一个产品,当我单击该项目时,我需要从列表视图的适配器内部的单击中转到另一个片段.

我的适配器是:

package info.android.adapter;

import info.android.ProductFragment;
import info.android.R;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductOfferslistadapter extends BaseAdapter {

    private Context context;
    private ArrayList<info.android.model.ProductsOffers> navProOffers;

    public ProductOfferslistadapter(Context context, ArrayList<info.android.model.ProductsOffers> navProOffers) {
        this.context = context;
        this.navProOffers = navProOffers;
    }

    @Override
    public int getCount() {
        return navProOffers.size();     
    }

    @Override
    public info.android.model.ProductsOffers getItem(int position) {        
        return navProOffers.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.fragment_row, null);
        }

        convertView.setonClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                          // I NEED CLALL HERE FRAGMENT_PRODUCT.XML                             
              }
            });

        ImageView img = (ImageView) convertView.findViewById(R.id.image); 

        TextView txtCodigo = (TextView) convertView.findViewById(R.id.txtCodigo);
        TextView txtCiudad = (TextView) convertView.findViewById(R.id.txtCiudad);               
        TextView txtVF = (TextView) convertView.findViewById(R.id.txtVF);

        String sVF =  Double.toString(getItem(position).ValorFinal) + "€";  

        txtVF.setText(sVF);
        txtCiudad.setText(getItem(position).ciudad);
        txtCodigo.setText(getItem(position).codigo);

        convertView.setTag(getItem(position).codigo);

        img.setimageBitmap(getItem(position).Imagen);

        return convertView;
    }
}

您必须假设所有代码都在工作.

如何转到适配器内的产品Fragment?

解决方法:

您将需要在构造函数中传递它.
例如:

public class ProductOfferslistadapter extends BaseAdapter
{
 private Context context;
 private ArrayList<info.android.model.ProductsOffers> navProOffers;
 Fragment myFragment;

 public ProductOfferslistadapter(Context context, ArrayList<info.android.model.ProductsOffers> navProOffers, Fragment myFragment) 
 {
    this.context = context;
    this.myFragment = myFragment;
    this.navProOffers = navProOffers;
 }

...

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...