views:

154

answers:

2

Hello, i have one doubt. I have an iteration of TextViews, and what i want is when i click in one TextView , i want stop the iteration and open a web, who can i know what TextView as been click on? i have this code:

Iterator<TextView> it = text.iterator();
   while(it.hasNext()){

 test = it.next();




 test.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
               //mWebView = (WebView) findViewById(R.id.webview);
               mWebView.setWebViewClient(new WebViewClient() {
                   @Override
                   public boolean shouldOverrideUrlLoading(WebView view, String url) {
                       view.loadUrl(url);
                       return true;
                   }
               });

           mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.loadUrl(url);


              }


              });



      // condition to stop the iteration when i click on TextView 
      }

And what i want is the condition to stop the iteration when i click on the TextView that i want see, i try using some methods that are in the TextView and don't work. Anyone can help me? I have the iteration of TextViews because i want to do this dynamic, and i don't know the TextView who as click, and i want to know what TextView was click to stop the iteration, because if i don't stop this, for example if i have 3 TextView they will open the same web.

Thanks and forgive my English

A: 

I'm not sure I understand you entirely but from what I understand you want to stop the Iteration when you click on a TextView.

So one way you can do it is. Declare a boolean property for this class to use to control the loop, in this case I called it isStop and initial value with false.

 while(it.hasNext() && !isStop){
...
    }

then

public void onClick(View v) {
isStop = true;
//mWebView = (WebView) findViewById(R.id.webview);
               mWebView.setWebViewClient(new WebViewClient() {
                   @Override
                   public boolean shouldOverrideUrlLoading(WebView view, String url) {
                       view.loadUrl(url);
                       return true;
                   }
               });

So when you click on a TextView the flag will turn off the loop.

RobGThai
Thank you for your answer, but i find the solution to what i want. I know the post that i put it's not clear. So i'm going to put the solution to what i want.
sgiro
A: 

The solution to what i wanted:

On the Activity i create this.

OnClickListener s = new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                text = (TextView) findViewById(v.getId());
                mWebView.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }
                });
                mWebView.getSettings().setJavaScriptEnabled(true);
                mWebView.loadUrl(url);
            }
        };

Iterator it = text.iterator(); while(it.hasNext()){

            text = it.next();





            text.setOnClickListener(s);



        }
sgiro