• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Add 1 to the text a textview on click

cr5315

Android Enthusiast
I have a TextView that is supposed to count how many times a user clicks on a link in a webview. I have the changing the textview set up, but I haven't done any work with the numbers before so I don't know how to set that up.

Here's the onClick code:

Code:
private class HelloWebViewClient extends WebViewClient {
	    @Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        view.loadUrl(url);
	        final TextView mTextView = (TextView) findViewById(R.id.jesusClicks);
	        mTextView.setText("Clicks: X");
	        return true;
	    }
	}

What I'm trying to do is set the X to how many times the user has clicked a link. I've done some searching on developer.android.com but I wasn't able to find anything that worked for me and I'm pretty sure that what I'm trying to do is quite basic, but I'm still kind of new to Android developing.
Any ideas?
 
Code:
private class HelloWebViewClient extends WebViewClient {
	    @Override
            int X = 0;
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        view.loadUrl(url);
	        final TextView mTextView = (TextView) findViewById(R.id.jesusClicks);
                X++;
	        mTextView.setText("Clicks" + Integer.toString(X));
	        return true;
	    }
	}

Just be sure to declare the variable "X" outside of your onClick.
 
Back
Top Bottom