Today we will learn Layout, Activity and Use of OnclickListener.
What we need to go to the first two Android Activity file. You've taken the first Android Application Project atomically a new file will be created in an Activity. Activity to a new file when you File> New> Other> Android Folder> Android Activity by clicking on the Next Blank Activity Activity of the new name, click on Finish.
Now we have two XML layout.
From the left-hand Palette activity_main.xml Text view, EditText, Button layouts to create drugs like below.
Now we'll Main Activity .java file. From here our EditText and Button's two EditText et; Button bt; Thus, you need to Declare.
Now we have the onCreate method, the setContentView (R.layout.activity_main); Down
et = (EditText) findViewById (R. id. editText);
bt = (Button) findViewById (R. id. button1);
Thus, you need to initialize. Here R.id. Activity_main.xml on the editText and Button
Id that was used, it will give him directions.
ooeyasinooCode hailaitara - Double-click on the code, copy the code to
What we need to go to the first two Android Activity file. You've taken the first Android Application Project atomically a new file will be created in an Activity. Activity to a new file when you File> New> Other> Android Folder> Android Activity by clicking on the Next Blank Activity Activity of the new name, click on Finish.
Now we have two XML layout.
From the left-hand Palette activity_main.xml Text view, EditText, Button layouts to create drugs like below.
Now we have the onCreate method, the setContentView (R.layout.activity_main); Down
et = (EditText) findViewById (R. id. editText);
bt = (Button) findViewById (R. id. button1);
Thus, you need to initialize. Here R.id. Activity_main.xml on the editText and Button
Id that was used, it will give him directions.
ooeyasinooCode hailaitara - Double-click on the code, copy the code to
<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:orientation= "vertical" android:gravity= "center" > <TextView android:id= "@+id/textView1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "@string/yourname" android:textAppearance= "?android:attr/textAppearanceMedium" /> <EditText android:id= "@+id/editText" android:gravity= "center" android:hint= "@string/editname" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "20sp" android:layout_marginBottom= "20sp" android:ems= "10" /> <Button android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "@string/Click" />
Clicking on the button will set onClickListener to Listen. Activity is the new flights SecondActivity Declare Intent to you. activity_main.xml to send data from the input text's intent. putExtra ("your_name", et. getText (). toString ());
ooeyasinooCode hailaitara - Double-click on the code, copy the code to
package com.coderart.androidpractise; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { EditText et; Button bt; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText) findViewById(R.id.editText); bt = (Button) findViewById(R.id.button1); bt.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(MainActivity. this , SecondActivity. class ); intent.putExtra( "your_name" , et.getText().toString()); startActivity(intent); } }); }
Thus, you need to Declare. Here your_name SecondActivity on the needs of the Id. The intent would be to start with the startActivity. Anarupabhabe SecondActivity.java also Textview, Button widget that will give the Declare and initialize. And textView2.setText ("Welcome \ n" + getIntent (). GetStringExtra ("your_name"));
The value had been in the input text will be displayed. Thus, the intent of onClicklistener distinguished GoBack button should be active. This layout, activity, and that this discussion about onClicklistener. This project's code here grab it. |
No comments:
Post a Comment