Click Handler

Click Handler Android Java example source code. Open new class as activity and open URL in browser.
In layout.xml file:

<Button android:text="Click me" android:id="@+id/btnOpenClass" android:layout_width="fill_parent"
 android:layout_height="wrap_content" android:onClick="@string/clickHandler">

In string.xml

<string name="clickHandler">myClickHandler</string>

In MainClass.java file

	public void myClickHandler(View view) {
		switch (view.getId()) {
		// open new class as activity
		case R.id.btnOpenClass: {
				Intent pictureActivity = new Intent(getBaseContext(),
						MyClass.class);
				startActivity(pictureActivity);
		}
		break;			
 
		case R.id.btnAbout: {
			//aboutDialogCreate();
		}
			break;
 
		// open url	
		 case R.id.btnHome: {
		 String url = "http://android.okhelp.cz/";
		 Intent i = new Intent(Intent.ACTION_VIEW);
		 i.setData(Uri.parse(url));
		 startActivity(i);
		 }break;
 
		}
 
	}// end myClickHandler
 
// listener .. if click on button will scrolling to mTextView bottom
private OnClickListener mButtonListener = new OnClickListener() {
	    public void onClick(View v) {
	      // do something when the button is clicked
	    int nBottom =	mTextView.getBottom();
	    hScrollView.scrollTo(0, nBottom);
	    }
	};
This entry was posted in Android Examples Code and tagged , , , , . Bookmark the permalink.


Comments are closed.



3,965 views