23.07.2015 Views

Android Tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

android:editable<br />

android:text<br />

If set, specifies that this TextView has an input method.<br />

This is the Text to display.<br />

Inherited from android.view.View Class:<br />

Attribute<br />

android:background<br />

android:contentDescription<br />

android:id<br />

android:onClick<br />

android:visibility<br />

Description<br />

This is a drawable to use as the background.<br />

This defines text that briefly describes content of the view.<br />

This supplies an identifier name for this view,<br />

This is the name of the method in this View's context to invoke when the view is<br />

clicked.<br />

This controls the initial visibility of the view.<br />

Example<br />

This example will take you through simple steps to show how to create your own <strong>Android</strong> application using Linear<br />

Layout and ToggleButton.<br />

Step Description<br />

1<br />

You will use Eclipse IDE to create an <strong>Android</strong> application and name it as GUIDemo7 under a<br />

package com.example.guidemo7 as explained in the Hello World Example chapter.<br />

2 Modify src/MainActivity.java file to add a click event.<br />

2 Modify the default content of res/layout/activity_main.xml file to include <strong>Android</strong> UI control.<br />

3 Define required constants in res/values/strings.xml file<br />

4 Run the application to launch <strong>Android</strong> emulator and verify the result of the changes done in the application.<br />

Following is the content of the modified main activity filesrc/com.example.guidemo7/MainActivity.java. This file<br />

can include each of the fundamental lifecycle methods.<br />

package com.example.guidemo7;<br />

import android.os.Bundle;<br />

import android.app.Activity;<br />

import android.view.Menu;<br />

import android.view.View;<br />

import android.view.View.OnClickListener;<br />

import android.widget.Button;<br />

import android.widget.Toast;<br />

import android.widget.ToggleButton;<br />

public class MainActivity extends Activity {<br />

private ToggleButton toggleBtn1, toggleBtn2;<br />

private Button btResult;<br />

@Override<br />

protected void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

setContentView(R.layout.activity_main);<br />

TUTORIALS POINT<br />

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!