onClick事件不触发

onClick事件不触发

本文介绍了android onClick事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要一个帮助,因为它的唯一的东西不工作在我的应用程序。
我有一个listview由扩展BaseAdapter的适配器管理。

I really need a help on this point because its the only thing not working in my app.I have a listview managed by an adapter that is extending BaseAdapter.

在getview函数im中使用convertView设置一个OnClickListener。
当我触摸屏幕时,OnClickListener工作得很好,但是如果我使用HTC Desire的轨迹球,我看到屏幕上的行闪烁,但OnClickListener没有被调用...

In the getview function im using the convertView to set up a OnClickListener.This OnClickListener work well when I am touching the screen but if I use the trackball of the HTC Desire, I see the row flashing on the screen, but the OnClickListener is not called...

我已阅读android开发指南:
,它说我应该从轨迹球接收一个onClick事件...

I've read the android dev guide : http://developer.android.com/guide/topics/ui/ui-events.htmland its say that I should receive a onClick event from the trackball...

我把这里的getview代码放在case,以防有人看到任何奇怪的东西。如果你对我能做什么有任何想法,请让我知道。

Im putting here my getview code in case someone see anything strange. If you have any idea on what I can do, please let me know.

public View getView(int position, View convertView, ViewGroup parent) {
        //ici on va utiliser un mécanisme de cache avec le Tag Holder
        MyTag holder;
        if (convertView == null){
            //On se branche sur le bon layout
            // convertView = inflater.inflate(android.R.layout.simple_list_item_2, null)
             convertView = inflater.inflate(R.layout.twolines, null);
            holder          = new MyTag();
            //on récupère les éléments du layout dans le holder
            holder.txtData  = (TextView)convertView.findViewById(R.id.productTitle);
            holder.txtExtra = (TextView)convertView.findViewById(android.R.id.text2);
            holder.imgScreenshot = (ImageView)convertView.findViewById(R.id.Screenshot);
            holder.imgFlag = (ImageView)convertView.findViewById(R.id.Flag);

            //holder.mLoginButton = (LoginButton) convertView.findViewById(R.id.login);
            holder.mPostButton = (ImageView) convertView.findViewById(R.id.postButton);

            //sauvegarde du holder
            convertView.setTag(holder);
        } else {
            holder = (MyTag)convertView.getTag();
        }


        //Facebook post button management
        holder.mPostButton.setOnClickListener((OnClickListener) new OnPostClickListener(convertView.getContext(),mFacebook, Long.toString(data[position].videoId), data[position].title, data[position].publisher, data[position].imageUrl));

        holder.mPostButton.setImageResource(com.cedemo.scan.utils.getPostButtonResId());


        //data update
        if(data[position].title != null)
            holder.txtData.setText(data[position].title);
        if(data[position].publisher != null)
            holder.txtExtra.setText(data[position].publisher);



        //get and set the language flag
        if(data[position].language != null)
            holder.imgFlag.setImageResource(com.cedemo.scan.utils.getFlag(data[position].language));

        //set the screenshot
        if(data[position].myVideoScreenshotBm != null)
            holder.imgScreenshot.setImageBitmap(data[position].myVideoScreenshotBm);


                    /* =================================================================

                       THIS FUNCTION IS NOT CALLED WHEN I CLICK ON THE TRACKBALL
                       BUT IS CALLED WHEN I TOUCH THE SCREEN.
                       WHEN I USE THE TRACKBALL THE SELECTED ROW IS FLASHING ONCE.

                       ================================================================= */
        //set the click mechanic if there is a valid video url
        if(data[position].url != null) {
            convertView.setOnClickListener((OnClickListener) new OnProductClickListener(position));


        }

        return convertView;
    }


推荐答案

推荐方法在ListView上 - 我想这是一个坏的风格,直接在适配器中设置侦听器。

Maybe you want to use the recommended method setOnItemClickListener() on the ListView instead - I guess it is a bad style to set the listeners directly within the adapter.

这篇关于android onClick事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:40