10
Blog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter the name of app And press next button and press next on second screen which comes and in third screen which looks like this

shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

Blog on making an app for making the text visible and invisible on clicking the button:

Firstly create the new android project.

Enter the name of app

And press next button and press next on second screen which comes and in third screen which looks like this

Page 2: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

If you want to change the icon of your app so you can browse from your desktop and press next button and choose empty activity and press next button

Page 3: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

After this the page open will look like this

Click on activity_main.xml which is highlighted on picture

Now this is your layout code so now write the following code to add a button to your screen and a textview

Page 4: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${packageName}.${activityClass}" >

<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="14dp" android:text = "Hello world" android:visibility="invisible" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text = "Button" />

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text = "Button" />

</RelativeLayout>

Your code will look like this

Page 5: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

Now open the MainActivity.java file

It will look like this

Now add the following code to make button clickable and show the text on clicking it

Page 6: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;

public class MainActivity extends Activity {TextView tv;Button b,b1;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv=(TextView)findViewById(R.id.textView1); b=(Button)findViewById(R.id.button1); b1=(Button)findViewById(R.id.button2); b.bringToFront(); b1.setVisibility(View.GONE); b.setOnClickListener(new OnClickListener() {

@Overridepublic void onClick(View v) {

// TODO Auto-generated method stubtv.setVisibility(View.VISIBLE);b.setVisibility(View.GONE);b1.setVisibility(View.VISIBLE);

}});

b1.setOnClickListener(new OnClickListener() {

@Overridepublic void onClick(View v) {

// TODO Auto-generated method stubtv.setVisibility(View.GONE);b1.setVisibility(View.GONE);b.setVisibility(View.VISIBLE);

}});

} }

Your code will look like it

Page 7: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

The sections which are circled in this you have to import their widgets .this can be done by pointing over the text and screen will comes like this.

Same do for all the 4 of them.

And your application is created now

Page 8: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

Now create the avd

Click on new button and follow the instructions given

Now right click on your project and run as given

Page 9: shanu262701.files.wordpress.com  · Web viewBlog on making an app for making the text visible and invisible on clicking the button: Firstly create the new android project. Enter

Now your emulator will open be patient till the emulator opens

And your app runs successfully..

For any query contact:- [email protected]