Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
  3. android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  4. android:paddingRight="@dimen/activity_horizontal_margin"
  5. android:paddingTop="@dimen/activity_vertical_margin"
  6. android:paddingBottom="@dimen/activity_vertical_margin"
  7. tools:context=".MainActivity"
  8. android:background="#daf1ff">
  9.  
  10. <LinearLayout
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:orientation="vertical">
  14. <TextView
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:text="USER REGISTRATION"
  18. android:textSize="30dp"
  19. android:layout_marginBottom="20dp"
  20. android:layout_marginLeft="22dp"
  21. android:textColor="#ed2d26"/>
  22. <LinearLayout
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:layout_marginBottom="10dp">
  26. <TextView android:text="Name: "
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:textSize="30dp"
  30. android:textColor="#fd7214"/>
  31. <EditText
  32. android:layout_width="250dp"
  33. android:layout_height="wrap_content" />
  34. </LinearLayout>
  35. <LinearLayout
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:layout_marginBottom="10dp">
  39. <TextView android:text="Gender: "
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:textSize="30dp"
  43. android:layout_marginRight="20dp"
  44. android:textColor="#fd7214"/>
  45. <RadioButton
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:text="Male"
  49. android:textColor="#a61f82"
  50. android:textSize="20dp"
  51. android:layout_marginLeft="10dp"/>
  52. <RadioButton
  53. android:layout_width="wrap_content"
  54. android:layout_height="wrap_content"
  55. android:text="Female"
  56. android:textColor="#a61f82"
  57. android:textSize="20dp"/>
  58. </LinearLayout>
  59. <LinearLayout
  60. android:layout_width="wrap_content"
  61. android:layout_height="wrap_content"
  62. android:layout_marginBottom="10dp">
  63. <TextView android:text="Country: "
  64. android:layout_width="wrap_content"
  65. android:layout_height="wrap_content"
  66. android:textSize="30dp"
  67. android:textColor="#fd7214"
  68. android:layout_marginRight="20dp"/>
  69. <Spinner
  70. android:layout_width="wrap_content"
  71. android:layout_height="wrap_content"
  72. android:id="@+id/spinner1"
  73. android:layout_marginTop="20dp">
  74. </Spinner>
  75. </LinearLayout>
  76. <LinearLayout
  77. android:layout_width="wrap_content"
  78. android:layout_height="wrap_content"
  79. android:layout_marginBottom="10dp">
  80. <TextView android:text="Address: "
  81. android:layout_width="wrap_content"
  82. android:layout_height="wrap_content"
  83. android:textSize="30dp"
  84. android:layout_marginRight="20dp"
  85. android:textColor="#fd7214"/>
  86. <EditText
  87. android:layout_width="250dp"
  88. android:layout_height="wrap_content" />
  89. </LinearLayout>
  90. <LinearLayout
  91. android:layout_width="wrap_content"
  92. android:layout_height="wrap_content"
  93. android:layout_marginBottom="10dp">
  94. <TextView android:text="Phone No: +91 "
  95. android:layout_width="wrap_content"
  96. android:layout_height="wrap_content"
  97. android:textSize="30dp"
  98. android:textColor="#fd7214"
  99. />
  100. <EditText
  101. android:layout_width="150dp"
  102. android:layout_height="wrap_content" />
  103. </LinearLayout>
  104. <LinearLayout
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:layout_marginBottom="50dp">
  108. <TextView android:text="E-mail: "
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:textSize="30dp"
  112. android:textColor="#fd7214"
  113. />
  114. <EditText
  115. android:layout_width="86dp"
  116. android:layout_height="wrap_content" />
  117. <Spinner
  118. android:layout_width="100dp"
  119. android:layout_height="wrap_content"
  120. android:id="@+id/spinner2"
  121. android:layout_marginTop="20dp">
  122. </Spinner>
  123. <TextView
  124. android:layout_width="wrap_content"
  125. android:layout_height="wrap_content"
  126. android:text=".com "
  127. android:textSize="20dp"
  128. android:textColor="#ff0080"/>
  129. </LinearLayout>
  130. <LinearLayout
  131. android:layout_width="wrap_content"
  132. android:layout_height="wrap_content">
  133. <Button
  134. android:layout_width="wrap_content"
  135. android:layout_height="wrap_content"
  136. android:text="REGISTER"
  137. android:textSize="25dp"
  138. android:layout_marginRight="70dp"
  139. android:id="@+id/register"/>
  140. <Button
  141. android:layout_width="wrap_content"
  142. android:layout_height="wrap_content"
  143. android:text="CANCEL"
  144. android:textSize="25dp"
  145. android:id="@+id/cancel"/>
  146. </LinearLayout>
  147.  
  148. </LinearLayout>
  149.  
  150. package com.example.sreelakshmi.myuser;
  151.  
  152. import android.app.Activity;
  153. import android.support.v7.app.ActionBarActivity;
  154. import android.os.Bundle;
  155. import android.view.Menu;
  156. import android.view.MenuItem;
  157. import android.view.View;
  158. import android.widget.AdapterView;
  159. import android.widget.ArrayAdapter;
  160. import android.widget.Button;
  161. import android.widget.Spinner;
  162. import android.widget.Toast;
  163.  
  164.  
  165. public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener {
  166.  
  167. String[] country=new String[]{"India","Japan","Canada","US","Others"};
  168. String[] mailid=new String[]{"@ gmail","@ yahoo","@ rediffmail","@ hotmail","@ godrej"};
  169. Spinner spin1=(Spinner)findViewById(R.id.spinner1);
  170. Spinner spin2=(Spinner)findViewById(R.id.spinner2);
  171. @Override
  172. protected void onCreate(Bundle savedInstanceState) {
  173. super.onCreate(savedInstanceState);
  174. setContentView(R.layout.activity_main);
  175. ArrayAdapter a1=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,country);
  176. a1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  177. spin1.setAdapter(a1);
  178. ArrayAdapter a2=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,mailid);
  179. a2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  180. spin2.setAdapter(a2);
  181. Button b1=(Button)findViewById(R.id.register);
  182. Button b2=(Button)findViewById(R.id.cancel);
  183. b1.setOnClickListener(new View.OnClickListener() {
  184. @Override
  185. public void onClick(View v) {
  186. Toast.makeText(getApplicationContext(),"Registration Successful!",Toast.LENGTH_LONG).show();
  187. }
  188. });
  189. b2.setOnClickListener(new View.OnClickListener() {
  190. @Override
  191. public void onClick(View v) {
  192. finish();
  193. }
  194. });
  195. spin1.setOnItemSelectedListener(this);
  196. spin2.setOnItemSelectedListener(this);
  197. }
  198.  
  199. @Override
  200. public boolean onCreateOptionsMenu(Menu menu) {
  201. // Inflate the menu; this adds items to the action bar if it is present.
  202. getMenuInflater().inflate(R.menu.menu_main, menu);
  203. return true;
  204. }
  205. @Override
  206. public boolean onOptionsItemSelected(MenuItem item) {
  207. // Handle action bar item clicks here. The action bar will
  208. // automatically handle clicks on the Home/Up button, so long
  209. // as you specify a parent activity in AndroidManifest.xml.
  210. int id = item.getItemId();
  211.  
  212. //noinspection SimplifiableIfStatement
  213. if (id == R.id.action_settings) {
  214. return true;
  215. }
  216.  
  217. return super.onOptionsItemSelected(item);
  218. }
  219.  
  220. @Override
  221. public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
  222. long arg3) {
  223. switch(arg0.getId()){
  224. case R.id.spinner1 :
  225. Toast.makeText(getApplicationContext(),country[arg2],Toast.LENGTH_LONG).show();
  226. break;
  227. case R.id.spinner2 :
  228. //Your Another Action Here.
  229. Toast.makeText(getApplicationContext(),mailid[arg2],Toast.LENGTH_LONG).show();
  230. break;
  231. }
  232. }
  233.  
  234. @Override
  235. public void onNothingSelected(AdapterView<?> parent) {
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement