当我在Item中显示带有PublisherAdView的广告时,ListView项目无法点击

时间:2015-03-13 19:33:11

标签: android listview adview

我需要在ListView项目中显示一个自定义的PublisherAdView,但该项目有一个Action,如果用户点击Ad之外(巫婆通向赞助商网址),则必须调用此操作,(我知道,这很奇怪)广告格式,但他们想要这种方式)。

如果未加载广告,则ListView项目点击有效,但当PublisherAdView显示广告时,该监听器将不再有效。

这是有关我正在努力实现的更多信息的屏幕截图:

Screnshot with some infos

我们这里有我的代码:

Categoria.java

ListView list=(ListView) v.findViewById(R.id_categoria.list);

adapter = new CategoriaAdapter(getActivity(), listaRec);
list.setAdapter(adapter);

// Click event for single list row
 (new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1,
            int arg2, long arg3) {

        Bundle parametros = new Bundle();

        if (listaRec.get(arg2).get("vai").equals("patrocinada")) {
            //action of the list with the PublisherAdView.
        } else {
            //action for all other items.
        }

    }
}

CategoriaAdapter

public class CategoriaAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;

    public CategoriaAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


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

    @Override
    public Object getItem(int position) {
        return position;        }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        SharedPreferences prefs = activity.getSharedPreferences("session", 0);

        HashMap<String, String> dados = null;

        if(convertView==null) {
            vi = inflater.inflate(R.layout.lista_categoria, null);
            dados = data.get(position);
        }

        TextView categoria = (TextView)vi.findViewById(R.id.lista_categoria_texto);
        LinearLayout layoutAd = (LinearLayout)vi.findViewById(R.id.lista_categoria_adView);

        // Setting all values in listview
        if (dados != null) {

            categoria.setText(dados.get("categoria"));

            if (dados.get("chave").equals("patrocinada"){

                layoutAd.setVisibility(View.VISIBLE);
                List<AdUnit> adUnits = AdUnitList.getAdUnitByCategoria(Menu.adUnits, 0);

                /* No big deal here. this method just build the name of the DFP ID/ad position and call addView() to the layout I pass (layoutAd)
                 * Eg: /10101010/<my_prefix>_selomediabox in this case
                 */
                Ads.setAd(AdUnit.getAdUnit(adUnits, "selomediabox"), layoutAd, activity);
            }
        }

        return vi;
    }
}

lista_categoria.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/select_item_bg"
    android:orientation="horizontal"
    android:id="@+id/lista_categoria_main"
    android:padding="5dip" >

    <TextView
        android:id="@+id/lista_categoria_texto"
        style="@style/categoria_listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:padding="5dp" />

    <LinearLayout
        android:id="@+id/lista_categoria_adView"
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:layout_toLeftOf="@+id/lista_categoria_seta"
        android:layout_marginRight="5dp"
        android:orientation="horizontal"
        android:layout_centerVertical="true">

    </LinearLayout>

    <ImageView
        android:id="@+id/lista_categoria_seta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:src="@drawable/seta_vermelha" />

</RelativeLayout>

有没有人知道PublisherAdView发生了什么覆盖我的“list.setOnItemClickListener”?

谢谢!

0 个答案:

没有答案