简体   繁体   English

Linkify的clickable方法会阻止listview click方法

[英]Linkify's clickable method blocks listview click method

Hi i have a listview with textview in every row with a text linkified with defined pattern in it , i use this small code to make linkified items can be clickable and call another activity in my app.But before that i am using imaview above the list to make navigation appear on listview , when i added 嗨,我有一个列表视图,每一行都有一个textview,其中的文本链接了定义的模式,我使用这个小代码使链接的项目可以单击并在我的应用程序中调用另一个活动。但是在此之前,我在列表上方使用了imaview当我添加时,使导航出现在listview上

    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Pattern Matcher = Pattern.compile("pattern here");
    String Url = "sth://";
    Linkify.addLinks(entrySpan, Matcher, Url);

Instead of onClick method of listview on just linkfy clicks are working , but i have to make them work bot 而不是只在linkfy点击上运行listview的onClick方法,但是我必须使它们工作自动

Here is code that i am using for listview click method but this seems never firing after setting linkify set movement , i am switching back and forth between Vısıble and Gone after every click. 这是我用于listview click方法的代码,但是在设置linkify set move之后,这似乎从未触发过,每次单击后,我都会在Vısıble和Gone之间来回切换。

getListView().setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                if(Entry.totalPageNumber>1){
                    //if no more than one page exist no need to navigate

                    if(show == false){
                        findViewById(R.id.back).setVisibility(View.VISIBLE);
                        findViewById(R.id.forward).setVisibility(View.VISIBLE);
                        findViewById(R.id.start).setVisibility(View.VISIBLE);
                        findViewById(R.id.last).setVisibility(View.VISIBLE);
                        show=true;
                    }else if(show==true){
                        findViewById(R.id.back).setVisibility(View.GONE);
                        findViewById(R.id.forward).setVisibility(View.GONE);
                        findViewById(R.id.start).setVisibility(View.GONE);
                        findViewById(R.id.last).setVisibility(View.GONE);
                        show=false;
                    }
                }
            }
        });

How to resolve this problem?? 如何解决这个问题?

As far as I know if you add a button in a listview item then you cannot select that List item any more. 据我所知,如果您在列表视图项中添加按钮,则无法再选择该列表项。 You have then to use a more complicated techniques of creating a custom adapter and using getView method to control the selection with setTag and getTag for each button. 然后,您必须使用更复杂的技术来创建自定义适配器,并使用getView方法通过每个按钮的setTag和getTag控制选择。 This may not be easy for a beginner but it is necessary to learn. 对于初学者来说这可能并不容易,但有必要学习。

Here is one simple example to start with: http://androidforbeginners.blogspot.com/2010/03/clicking-buttons-in-listview-row.html 这是一个简单的示例,开头为: http : //androidforbeginners.blogspot.com/2010/03/clicking-buttons-in-listview-row.html

There is also a problem with list being recycled. 列表被回收还有一个问题。 This means that if there are 10 rows on the screen the 11th will show to be selected or changed too when you scroll and 21st and so on... here getView has to explicitly control the layout of each listitem by using if(condition which determins layout){...code...}else{...code...} 这意味着如果屏幕上有10行,则在滚动时会显示第11行也将被选择或更改;在第21行,依此类推...在这里,getView必须使用if(condition确定条件,显式控制每个列表项的布局布局){...代码...}否则{...代码...}

I resolved it , just moved the onClickListener implementation into my getView method which draw textview and directly apply onClickListener to textView and finally both of them working happily 我解决了它,只是将onClickListener实现移到了我的getView方法中,该方法绘制了textview并将onClickListener直接应用于textView,最后两者都可以快乐地工作

TextView textView = (TextView) mView.findViewById(R.id.entryRowTextView);


textView.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            // TODO Auto-generated method stub
                            if(Entry.totalPageNumber>1){
                                //if no more than one page exist no need to navigate
                                Log.d(EKSI, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                if(show == false){
                                    findViewById(R.id.back).setVisibility(View.VISIBLE);
                                    findViewById(R.id.forward).setVisibility(View.VISIBLE);
                                    findViewById(R.id.start).setVisibility(View.VISIBLE);
                                    findViewById(R.id.last).setVisibility(View.VISIBLE);
                                    show=true;
                                }else if(show==true){
                                    findViewById(R.id.back).setVisibility(View.GONE);
                                    findViewById(R.id.forward).setVisibility(View.GONE);
                                    findViewById(R.id.start).setVisibility(View.GONE);
                                    findViewById(R.id.last).setVisibility(View.GONE);
                                    show=false;
                                }
                            }
                        }
                    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM