Sunteți pe pagina 1din 23

1.Calculator for performing arithmetic operations.

Source code:
Java:

import ​android.support.v7.app.AppCompatActivity;
import ​android.os.Bundle;
import ​android.view.Menu;
import ​android.view.MenuItem;
import ​android.view.View;
import ​android.widget.Button;
import ​android.widget.EditText;

public class ​MainActivity ​extends ​AppCompatActivity {

Button ​button0 ​, ​button1 ​, ​button2 ​, ​button3 ​, ​button4 ​, ​button5 ​, ​button6 ​,


​button7 ​, ​button8 ​, ​button9 ​, ​buttonAdd ​, ​buttonSub ​, ​buttonDivision ​,
​buttonMul ​, ​button10 ​, ​buttonC ​, ​buttonEqual ​;

EditText ​edt1 ​;

​float ​mValueOne ​, ​mValueTwo ​;

​boolean ​mAddition ​, ​mSubtract ​,​mMultiplication ​,​mDivision ​;

​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.​activity_main​);

​button0 ​= (Button) findViewById(R.id.​button0) ​ ;


​button1 ​= (Button) findViewById(R.id.​button1) ​ ;
​button2 ​= (Button) findViewById(R.id.​button2) ​ ;
​button3 ​= (Button) findViewById(R.id.​button3) ​ ;
​button4 ​= (Button) findViewById(R.id.​button4) ​ ;
​button5 ​= (Button) findViewById(R.id.​button5) ​ ;
​button6 ​= (Button) findViewById(R.id.​button6) ​ ;
​button7 ​= (Button) findViewById(R.id.​button7) ​ ;
​button8 ​= (Button) findViewById(R.id.​button8) ​ ;
​button9 ​= (Button) findViewById(R.id.​button9) ​ ;
​button10 ​= (Button) findViewById(R.id.​button10​);
​buttonAdd ​= (Button) findViewById(R.id.​buttonadd​);
​buttonSub ​= (Button) findViewById(R.id.​buttonsub​);
​buttonMul ​= (Button) findViewById(R.id.​buttonmul​);
​buttonDivision ​= (Button) findViewById(R.id.​buttondiv​);
​buttonC ​= (Button) findViewById(R.id.​buttonC) ​ ;
​buttonEqual ​= (Button) findViewById(R.id.​buttoneql​);
​edt1 ​= (EditText) findViewById(R.id.​edt1​);
​button1​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"1"​);
}
});

​button2​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"2"​);
}
});

​button3​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"3"​);
}
});

​button4​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"4"​);
}
});

​button5​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"5"​);
}
});

​button6​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"6"​);
}
});

​button7​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"7"​);
}
});
​button8​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"8"​);
}
});

​button9​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"9"​);
}
});

​button0​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"0"​);
}
});

​buttonAdd​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {

​if ​(​edt1 ​== ​null​){


​edt1​.setText(​""​);
}​else ​{
​ ​edt1​.getText() + ​""​);
​mValueOne ​= Float.​parseFloat(
​mAddition ​= ​true​;
​edt1​.setText(​null​);
}
}
});

​buttonSub​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​mValueOne ​= Float.​parseFloat​(​edt1​.getText() + ​""​);
​mSubtract ​= ​true ​;
​edt1​.setText(​null​);
}
});

​buttonMul​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​mValueOne ​= Float.​parseFloat​(​edt1​.getText() + ​""​);
​mMultiplication ​= ​true ​;
​edt1​.setText(​null​);
}
});

​buttonDivision​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​mValueOne ​= Float.​parseFloat​(​edt1​.getText()+​""​);
​mDivision ​= ​true ​;
​edt1​.setText(​null​);
}
});

​buttonEqual​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​mValueTwo ​= Float.​parseFloat​(​edt1​.getText() + ​""​);

​if ​(​mAddition ​== ​true​){

​edt1​.setText(​mValueOne ​+ ​mValueTwo ​+​""​);


​mAddition​=​false​;
}

​if ​(​mSubtract ​== ​true​){


​edt1​.setText(​mValueOne ​- ​mValueTwo​+​""​);
​mSubtract​=​false​;
}

​if ​(​mMultiplication ​== ​true​){


​edt1​.setText(​mValueOne ​* ​mValueTwo​+​""​);
​mMultiplication​=​false​;
}

​if ​(​mDivision ​== ​true​){


​edt1​.setText(​mValueOne ​/ ​mValueTwo​+​""​);
​mDivision​=​false​;
}
}
});

​buttonC​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​""​);
}
});

​button10​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
​edt1​.setText(​edt1​.getText()+​"."​);
}
});
}

XML:

<?​xml version=​"1.0" ​encoding=​"utf-8"​?>


<​RelativeLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
xmlns:​tools​=​"http://schemas.android.com/tools"
android​:layout_width=​"match_parent"
android​:layout_height=​"match_parent"
tools​:context=​".MainActivity"​>

<​EditText
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:id=​"@+id/edt1"​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"1"
​android​:id=​"@+id/button1"
​android​:layout_marginTop=​"94dp"
​android​:layout_below=​"@+id/edt1"
​android​:layout_toStartOf=​"@+id/button4"
​android​:layout_alignRight=​"@+id/button4"
​android​:layout_alignEnd=​"@+id/button4" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"2"
​android​:id=​"@+id/button2"
​android​:layout_alignTop=​"@+id/button1"
​android​:layout_toLeftOf=​"@+id/button3"
​android​:layout_toStartOf=​"@+id/button3" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"3"
​android​:id=​"@+id/button3"
​android​:layout_alignTop=​"@+id/button2"
​android​:layout_centerHorizontal=​"true" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"4"
​android​:id=​"@+id/button4"
​android​:layout_below=​"@+id/button1"
​android​:layout_toLeftOf=​"@+id/button2" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"5"
​android​:id=​"@+id/button5"
​android​:layout_alignBottom=​"@+id/button4"
​android​:layout_alignLeft=​"@+id/button2"
​android​:layout_alignStart=​"@+id/button2" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"6"
​android​:id=​"@+id/button6"
​android​:layout_below=​"@+id/button3"
​android​:layout_alignLeft=​"@+id/button3"
​android​:layout_alignStart=​"@+id/button3" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"7"
​android​:id=​"@+id/button7"
​android​:layout_below=​"@+id/button4"
​android​:layout_toLeftOf=​"@+id/button2" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"8"
​android​:id=​"@+id/button8"
​android​:layout_below=​"@+id/button5"
​android​:layout_alignLeft=​"@+id/button5"
​android​:layout_alignStart=​"@+id/button5" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"9"
​android​:id=​"@+id/button9"
​android​:layout_below=​"@+id/button6"
​android​:layout_alignLeft=​"@+id/button6"
​android​:layout_alignStart=​"@+id/button6" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"+"
​android​:id=​"@+id/buttonadd"
​android​:layout_alignTop=​"@+id/button3"
​android​:layout_toRightOf=​"@+id/button3"
​android​:layout_marginLeft=​"46dp"
​android​:layout_marginStart=​"46dp"
​android​:layout_alignRight=​"@+id/edt1"
​android​:layout_alignEnd=​"@+id/edt1" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"-"
​android​:id=​"@+id/buttonsub"
​android​:layout_below=​"@+id/buttonadd"
​android​:layout_alignLeft=​"@+id/buttonadd"
​android​:layout_alignStart=​"@+id/buttonadd"
​android​:layout_alignRight=​"@+id/buttonadd"
​android​:layout_alignEnd=​"@+id/buttonadd" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"*"
​android​:id=​"@+id/buttonmul"
​android​:layout_below=​"@+id/buttonsub"
​android​:layout_alignLeft=​"@+id/buttonsub"
​android​:layout_alignStart=​"@+id/buttonsub"
​android​:layout_alignParentRight=​"true"
​android​:layout_alignParentEnd=​"true" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"."
​android​:id=​"@+id/button10"
​android​:layout_below=​"@+id/button7"
​android​:layout_toLeftOf=​"@+id/button2" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"0"
​android​:id=​"@+id/button0"
​android​:layout_below=​"@+id/button8"
​android​:layout_alignLeft=​"@+id/button8"
​android​:layout_alignStart=​"@+id/button8" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"C"
​android​:id=​"@+id/buttonC"
​android​:layout_below=​"@+id/button9"
​android​:layout_alignLeft=​"@+id/button9"
​android​:layout_alignStart=​"@+id/button9" ​/>

<​Button
​style=​"?android:attr/buttonStyleSmall"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"/"
​android​:id=​"@+id/buttondiv"
​android​:layout_below=​"@+id/buttonmul"
​android​:layout_alignLeft=​"@+id/buttonmul"
​android​:layout_alignStart=​"@+id/buttonmul"
​android​:layout_alignRight=​"@+id/buttonmul"
​android​:layout_alignEnd=​"@+id/buttonmul" ​/>

<​Button
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"="
​android​:id=​"@+id/buttoneql"
​android​:layout_below=​"@+id/button0"
​android​:layout_marginTop=​"37dp"
​android​:layout_alignRight=​"@+id/buttondiv"
​android​:layout_alignEnd=​"@+id/buttondiv"
​android​:layout_alignLeft=​"@+id/button10"
​android​:layout_alignStart=​"@+id/button10" ​/>

</​RelativeLayout​>

Output:
2.Change image on button click

Source code:
Java:
package ​com.example.imagechange;

import ​android.support.v7.app.AppCompatActivity;
import ​android.os.Bundle;
import ​android.view.View;
import ​android.widget.Button;

public class ​MainActivity ​extends ​AppCompatActivity {


Button ​mPlayButton​;

​boolean ​isPlay ​= ​false​;


​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.​activity_main)​ ;
​mPlayButton ​= (Button) findViewById(R.id.​play​);
​// Default button, if need set it in xml via background="@drawable/default"
​mPlayButton​.setBackgroundResource(R.drawable.​image1) ​ ;
​mPlayButton​.setOnClickListener(​mTogglePlayButton​);
}

View.OnClickListener ​mTogglePlayButton ​= ​new ​View.OnClickListener(){

​@Override
​public void ​onClick(View v){
​// change your button background

​ f​(​isPlay​){
i
v.setBackgroundResource(R.drawable.​image1​);
}​else​{
v.setBackgroundResource(R.drawable.​image2​);
}

​isPlay ​= !​isPlay​; ​// reverse


​}

};
}

Xml:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​android​:layout_width=​"match_parent"
​android​:orientation=​"vertical"
​android​:layout_height=​"match_parent"
​tools​:context=​".MainActivity"​>

<​ImageView
​android​:layout_width=​"300dp"
​android​:layout_height=​"300dp"
​android​:id=​"@+id/image"​/>
<​Button
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content"
​android​:text=​"click"
​android​:id=​"@+id/play"​/>
</​LinearLayout​>
Output:
3.webview app
Source code:
Java:
package ​com.example.webview;

import ​android.app.Activity;
import ​android.support.v7.app.AppCompatActivity;
import ​android.os.Bundle;
import ​android.webkit.WebSettings;
import ​android.webkit.WebView;
import ​android.webkit.WebViewClient;

public class ​MainActivity ​extends ​Activity {


WebView ​wb​;
​private class ​HelloWebViewClient ​extends ​WebViewClient {
​@Override
​public boolean ​shouldOverrideUrlLoading(WebView view, String url) {
​return false​;
}
}
​/** Called when the activity is first created. */
​@Override
​public void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
​ ;
setContentView(R.layout.​activity_main)
​wb​=(WebView)findViewById(R.id.​webView1​);
​wb​.getSettings().setJavaScriptEnabled(​true​);
​wb​.getSettings().setLoadWithOverviewMode(​true​);
​wb​.getSettings().setUseWideViewPort(​true​);
​wb​.getSettings().setBuiltInZoomControls(​true​);
​ ;
​wb​.getSettings().setPluginState(WebSettings.PluginState.​ON)

​wb​.setWebViewClient(​new ​HelloWebViewClient());
​wb​.loadUrl(​"http://www.google.com"​);
}
}
Xml:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​android​:layout_width=​"match_parent"
​android​:layout_height=​"match_parent"
​tools​:context=​".MainActivity"​>

<​WebView
​android​:id=​"@+id/webView1"
​android​:layout_width=​"fill_parent"
​android​:layout_height=​"fill_parent"
​android​:layout_gravity=​"center" ​/>

</​LinearLayout​>
Note:
Add this to manifest
<​uses-permission ​android​:name=​"android.permission.INTERNET"​/>

Output:
4.create a listview and get listitem data on click.

Source code:
Java:
MainActivity.java:
package ​com.example.listviewexample;

import ​android.os.Bundle;
import ​android.view.View;
import ​android.widget.AdapterView;
import ​android.widget.ListView;
import ​android.widget.Toast;
import ​android.app.Activity;

public class ​MainActivity ​extends ​Activity {


ListView ​list​;
String[] ​web ​= {
​"Google Plus"​,
​"Twitter"​,
​"Windows"​,
​"Bing"​,
​"Itunes"​,
​"Wordpress"​,
​"Drupal"
​} ;
Integer[] ​imageId ​= {
R.drawable.​profile1,​
R.drawable.​profile2, ​
R.drawable.​profile3, ​
R.drawable.​profile4, ​
R.drawable.​profile5, ​
R.drawable.​profile1, ​
R.drawable.​profile3

​};

​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
​ ;
setContentView(R.layout.​activity_main)

CustomList adapter = ​new


​CustomList(MainActivity.​this​, ​web​, ​imageId​);
​list​=(ListView)findViewById(R.id.​list) ​ ;
​list​.setAdapter(adapter);
​list​.setOnItemClickListener(​new ​AdapterView.OnItemClickListener() {
​@Override
​public void ​onItemClick(AdapterView<?> parent, View view,
​int ​position, ​long ​id) {
​ MainActivity.​this​, ​"You Clicked at " ​+​web​[+ position],
Toast.​makeText(
Toast.​LENGTH_SHORT) ​ .show();

}
});

CustomList.java

package ​com.example.listviewexample;

import ​android.app.Activity;
import ​android.view.LayoutInflater;
import ​android.view.View;
import ​android.view.ViewGroup;
import ​android.widget.ArrayAdapter;
import ​android.widget.ImageView;
import ​android.widget.TextView;

public class ​CustomList ​extends ​ArrayAdapter<String>{

​private final ​Activity ​context​;


​private final ​String[] ​web​;
​private final ​Integer[] ​imageId​;
​public ​CustomList(Activity context,
String[] web, Integer[] imageId) {
​super​(context, R.layout.​list_single​, web);
​this​.​context ​= context;
​this​.​web ​= web;
​this​.​imageId ​= imageId;

}
​@Override
​public ​View getView(​int ​position, View view, ViewGroup parent) {
LayoutInflater inflater = ​context​.getLayoutInflater();
View rowView= inflater.inflate(R.layout.​list_single, ​ ​null​, ​true​);
TextView txtTitle = (TextView) rowView.findViewById(R.id.​txt​);

ImageView imageView = (ImageView) rowView.findViewById(R.id.​img​);


txtTitle.setText(​web​[position]);

imageView.setImageResource(​imageId​[position]);
​return ​rowView;
}
}
ListSingle.xml

<?​xml version=​"1.0" ​encoding=​"utf-8"​?>


<​TableLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​android​:layout_width=​"match_parent"
​android​:layout_height=​"match_parent" ​>
<​TableRow​>
<​ImageView
​android​:id=​"@+id/img"
​android​:layout_width=​"50dp"
​android​:layout_height=​"50dp"​/>

<​TextView
​android​:id=​"@+id/txt"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"50dp" ​/>

</​TableRow​>
</​TableLayout​>

Activity_main.xml

<?​xml version=​"1.0" ​encoding=​"utf-8"​?>


<​RelativeLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​android​:layout_width=​"match_parent"
​android​:layout_height=​"match_parent"
​tools​:context=​".MainActivity"​>

<​ListView
​android​:id=​"@+id/list"
​android​:layout_width=​"wrap_content"
​android​:layout_height=​"wrap_content" ​>

</​ListView​>

</​RelativeLayout​>

Output:
5.get user data and show the data in second activity.

Source code:
Java:
MainActivity.java:

package ​com.example.userdetails;

import ​android.content.Intent;
import ​android.os.Parcelable;
import ​android.support.v7.app.AppCompatActivity;
import ​android.os.Bundle;
import ​android.view.View;
import ​android.widget.Button;
import ​android.widget.EditText;

public class ​MainActivity ​extends ​AppCompatActivity {


EditText ​name​;
EditText ​address​;
EditText ​college​;
Button ​submit​;
​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.​activity_main)​ ;
​name ​= (EditText)findViewById(R.id.​name​);
​address ​= (EditText)findViewById(R.id.​adddress​);
​college ​= (EditText)findViewById(R.id.​college​);;
​ ;
​submit ​= (Button)findViewById(R.id.​submit)

​ ​name​.getText());
​final ​String nametext = String.​valueOf(

​submit​.setOnClickListener(​new ​View.OnClickListener() {
​@Override
​public void ​onClick(View v) {
Intent i = ​new ​Intent(MainActivity.​this​, SecondActivity.​class​);
i.putExtra(​"name"​, ​name​.getText().toString());
i.putExtra(​"address"​, ​address​.getText().toString());
i.putExtra(​"college"​, ​college​.getText().toString());
startActivity(i);

}
});

}
}
SecondActivity.java
package ​com.example.userdetails;
import ​android.content.Intent;
import ​android.support.v7.app.AppCompatActivity;
import ​android.os.Bundle;
import ​android.widget.TextView;

import ​org.w3c.dom.Text;

public class ​SecondActivity ​extends ​AppCompatActivity {


TextView ​nameView​;
TextView ​addressView​;
TextView ​collegeView​;
String ​value​;
​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
setContentView(R.layout.​activity_second​);
​nameView ​= (TextView)findViewById(R.id.​name1) ​ ;
​addressView ​= (TextView)findViewById(R.id.​address1) ​ ;
​collegeView ​=(TextView)findViewById(R.id.​college1​);

Intent i = getIntent();

String name = i.getStringExtra(​"name"​);


String address = i.getStringExtra(​"address"​);
String college = i.getStringExtra(​"college"​);
nameView​.setText(name);
addressView​.setText(address);
collegeView​.setText(college);
}

XML:
acitivity_main.xml:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​LinearLayout
​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​android​:layout_width=​"match_parent"
​android​:orientation=​"vertical"
​android​:layout_height=​"match_parent"
​tools​:context=​".MainActivity"​>

<​EditText
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:hint=​"enter name"
​android​:id=​"@+id/name"​/>

<​EditText
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:hint=​"enter address"
​android​:id=​"@+id/adddress"​/>

<​EditText
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:hint=​"enter college name"
​android​:id=​"@+id/college"​/>

<​Button
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:text=​"submit"
​android​:id=​"@+id/submit"​/>
</​LinearLayout​>
Activity_second.xml:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​android​:layout_width=​"match_parent"
​android​:layout_height=​"match_parent"
​android​:orientation=​"vertical"
​tools​:context=​".SecondActivity"​>
T<​TextView
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:textSize=​"20sp"
​android​:id=​"@+id/name1"​/>
<​TextView
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:textSize=​"20sp"
​android​:id=​"@+id/address1"​/>
<​TextView
​android​:layout_width=​"match_parent"
​android​:layout_height=​"wrap_content"
​android​:textSize=​"20sp"
​android​:id=​"@+id/college1"​/>
</​LinearLayout​>
Output:
6.develop an application using different GUI components.

Source code:
Java:
package ​com.example.geometricalfigures;

​ ndroid.support.v7.app.AppCompatActivity;
import a
import a​ ndroid.os.Bundle;

public class ​MainActivity ​extends ​AppCompatActivity {

​@Override
​protected void ​onCreate(Bundle savedInstanceState) {
​super​.onCreate(savedInstanceState);
​ ;
setContentView(R.layout.​activity_main)
}
}
Xml:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​LinearLayout ​xmlns:​android​=​"http://schemas.android.com/apk/res/android"
​xmlns:​app​=​"http://schemas.android.com/apk/res-auto"
​xmlns:​tools​=​"http://schemas.android.com/tools"
​android​:layout_width=​"match_parent"
​android​:layout_height=​"match_parent"
​android​:orientation=​"vertical"
​tools​:context=​".MainActivity"​>

<​RelativeLayout
​android​:layout_width=​"200dp"
​android​:layout_height=​"100dp"
​android​:background=​"#000000"​></​RelativeLayout​>
<​RelativeLayout
​android​:layout_width=​"100dp"
​android​:layout_height=​"100dp"
​android​:layout_marginTop=​"30dp"
​android​:background=​"#FF0000"​></​RelativeLayout​>
<​RelativeLayout
​android​:layout_width=​"200dp"
​android​:layout_height=​"200dp"
​android​:background=​"@drawable/triangle"​></​RelativeLayout​>
</​LinearLayout​>
Triangle Drawable:
<?​xml version=​"1.0" ​encoding=​"utf-8"​?>
<​layer-list ​xmlns:​android​=​"http://schemas.android.com/apk/res/android" ​>
<​item​>
<​rotate
​android​:fromDegrees=​"45"
​android​:toDegrees=​"45"
​android​:pivotX=​"-40%"
​android​:pivotY=​"87%" ​>
<​shape
​android​:shape=​"rectangle" ​>
<​stroke ​android​:color=​"#000000" ​android​:width=​"10dp"​/>
<​solid
​android​:color=​"#000000" ​/>
</​shape​>
</​rotate​>
</​item​>
</​layer-list​>

Output:

S-ar putea să vă placă și