Advertisement
Guest User

Help me

a guest
Apr 28th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. Main Activity
  2.  
  3. package com.example.tempele.dbexample;
  4.  
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13. EditText buckysInput;
  14. TextView buckysText;
  15. MyDBHandler dbHandler;
  16. EditText ppr;
  17. EditText numRides;
  18. double pprvar;
  19. int numridesvar;
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25.  
  26. buckysInput = (EditText) findViewById(R.id.buckysInput);
  27. buckysText = (TextView) findViewById(R.id.buckysText);
  28. ppr = (EditText) findViewById(R.id.ppr);
  29. numRides = (EditText) findViewById(R.id.numRides);
  30.  
  31. //pprvar = Double.parseDouble(ppr.getText().toString());
  32. //numridesvar = Integer.parseInt(numRides.getText().toString());
  33.  
  34. //pprvar = 1.2;
  35. //numridesvar = 1;
  36.  
  37. dbHandler = new MyDBHandler(this, null, null, 1);
  38. printDatabase();
  39.  
  40. }
  41.  
  42. //Add a product to the database
  43. public void addButtonClicked(View view){
  44.  
  45. Product product = new Product(buckysInput.getText().toString());
  46. Product priceper = new Product(ppr.getText().toString());
  47. Product rides = new Product(numRides.getText().toString());
  48.  
  49. dbHandler.addProduct(product, priceper, rides);
  50. printDatabase();
  51. }
  52.  
  53. //Delete items
  54. public void deleteButtonClicked(View view){
  55. String inputText = buckysInput.getText().toString();
  56. dbHandler.deleteProduct(inputText);
  57. printDatabase();
  58. }
  59.  
  60. //Print the database
  61. public void printDatabase(){
  62. String dbString = dbHandler.databaseToString();
  63. buckysText.setText(dbString);
  64. buckysInput.setText("");
  65. ppr.setText("");
  66. numRides.setText("");
  67. }
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. Product Activity
  85.  
  86.  
  87. package com.example.tempele.dbexample;
  88.  
  89. import android.support.v7.app.AppCompatActivity;
  90. import android.os.Bundle;
  91. import android.view.View;
  92. import android.widget.EditText;
  93. import android.widget.TextView;
  94.  
  95. public class MainActivity extends AppCompatActivity {
  96.  
  97. EditText buckysInput;
  98. TextView buckysText;
  99. MyDBHandler dbHandler;
  100. EditText ppr;
  101. EditText numRides;
  102. double pprvar;
  103. int numridesvar;
  104.  
  105. @Override
  106. protected void onCreate(Bundle savedInstanceState) {
  107. super.onCreate(savedInstanceState);
  108. setContentView(R.layout.activity_main);
  109.  
  110. buckysInput = (EditText) findViewById(R.id.buckysInput);
  111. buckysText = (TextView) findViewById(R.id.buckysText);
  112. ppr = (EditText) findViewById(R.id.ppr);
  113. numRides = (EditText) findViewById(R.id.numRides);
  114.  
  115. //pprvar = Double.parseDouble(ppr.getText().toString());
  116. //numridesvar = Integer.parseInt(numRides.getText().toString());
  117.  
  118. //pprvar = 1.2;
  119. //numridesvar = 1;
  120.  
  121. dbHandler = new MyDBHandler(this, null, null, 1);
  122. printDatabase();
  123.  
  124. }
  125.  
  126. //Add a product to the database
  127. public void addButtonClicked(View view){
  128.  
  129. Product product = new Product(buckysInput.getText().toString());
  130. Product priceper = new Product(ppr.getText().toString());
  131. Product rides = new Product(numRides.getText().toString());
  132.  
  133. dbHandler.addProduct(product, priceper, rides);
  134. printDatabase();
  135. }
  136.  
  137. //Delete items
  138. public void deleteButtonClicked(View view){
  139. String inputText = buckysInput.getText().toString();
  140. dbHandler.deleteProduct(inputText);
  141. printDatabase();
  142. }
  143.  
  144. //Print the database
  145. public void printDatabase(){
  146. String dbString = dbHandler.databaseToString();
  147. buckysText.setText(dbString);
  148. buckysInput.setText("");
  149. ppr.setText("");
  150. numRides.setText("");
  151. }
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159. MYDBHANDler activity
  160.  
  161.  
  162.  
  163. package com.example.tempele.dbexample;
  164.  
  165. import android.support.v7.app.AppCompatActivity;
  166. import android.os.Bundle;
  167. import android.view.View;
  168. import android.widget.EditText;
  169. import android.widget.TextView;
  170.  
  171. public class MainActivity extends AppCompatActivity {
  172.  
  173. EditText buckysInput;
  174. TextView buckysText;
  175. MyDBHandler dbHandler;
  176. EditText ppr;
  177. EditText numRides;
  178. double pprvar;
  179. int numridesvar;
  180.  
  181. @Override
  182. protected void onCreate(Bundle savedInstanceState) {
  183. super.onCreate(savedInstanceState);
  184. setContentView(R.layout.activity_main);
  185.  
  186. buckysInput = (EditText) findViewById(R.id.buckysInput);
  187. buckysText = (TextView) findViewById(R.id.buckysText);
  188. ppr = (EditText) findViewById(R.id.ppr);
  189. numRides = (EditText) findViewById(R.id.numRides);
  190.  
  191. //pprvar = Double.parseDouble(ppr.getText().toString());
  192. //numridesvar = Integer.parseInt(numRides.getText().toString());
  193.  
  194. //pprvar = 1.2;
  195. //numridesvar = 1;
  196.  
  197. dbHandler = new MyDBHandler(this, null, null, 1);
  198. printDatabase();
  199.  
  200. }
  201.  
  202. //Add a product to the database
  203. public void addButtonClicked(View view){
  204.  
  205. Product product = new Product(buckysInput.getText().toString());
  206. Product priceper = new Product(ppr.getText().toString());
  207. Product rides = new Product(numRides.getText().toString());
  208.  
  209. dbHandler.addProduct(product, priceper, rides);
  210. printDatabase();
  211. }
  212.  
  213. //Delete items
  214. public void deleteButtonClicked(View view){
  215. String inputText = buckysInput.getText().toString();
  216. dbHandler.deleteProduct(inputText);
  217. printDatabase();
  218. }
  219.  
  220. //Print the database
  221. public void printDatabase(){
  222. String dbString = dbHandler.databaseToString();
  223. buckysText.setText(dbString);
  224. buckysInput.setText("");
  225. ppr.setText("");
  226. numRides.setText("");
  227. }
  228.  
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. Activity_main.xml
  237.  
  238.  
  239. <?xml version="1.0" encoding="utf-8"?>
  240. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  241. xmlns:tools="http://schemas.android.com/tools"
  242. android:layout_width="match_parent"
  243. android:layout_height="match_parent"
  244. android:paddingBottom="@dimen/activity_vertical_margin"
  245. android:paddingLeft="@dimen/activity_horizontal_margin"
  246. android:paddingRight="@dimen/activity_horizontal_margin"
  247. android:paddingTop="@dimen/activity_vertical_margin"
  248. tools:context="com.example.tempele.dbexample.MainActivity">
  249.  
  250. <Button
  251. android:layout_width="wrap_content"
  252. android:layout_height="wrap_content"
  253. android:text="Add"
  254. android:id="@+id/addButton"
  255. android:layout_centerVertical="true"
  256. android:layout_toStartOf="@+id/buckysText" />
  257.  
  258. <Button
  259. android:layout_width="wrap_content"
  260. android:layout_height="wrap_content"
  261. android:text="Delete"
  262. android:id="@+id/deleteButton"
  263. android:layout_marginRight="24dp"
  264. android:onClick="deleteButtonClicked"
  265. android:layout_alignTop="@+id/addButton"
  266. android:layout_toEndOf="@+id/buckysText" />
  267.  
  268. <EditText
  269. android:layout_width="wrap_content"
  270. android:layout_height="wrap_content"
  271. android:id="@+id/buckysInput"
  272. android:width="250dp"
  273. android:layout_alignParentTop="true"
  274. android:layout_centerHorizontal="true"
  275. android:hint="Name" />
  276.  
  277. <TextView
  278. android:layout_width="wrap_content"
  279. android:layout_height="wrap_content"
  280. android:textAppearance="?android:attr/textAppearanceLarge"
  281. android:text="Large Text"
  282. android:id="@+id/buckysText"
  283. android:layout_below="@+id/addButton"
  284. android:layout_centerHorizontal="true"
  285. android:layout_marginTop="36dp" />
  286.  
  287. <EditText
  288. android:layout_width="wrap_content"
  289. android:layout_height="wrap_content"
  290. android:id="@+id/ppr"
  291. android:width="250dp"
  292. android:hint="Price per Ride"
  293. android:layout_marginTop="28dp"
  294. android:layout_below="@+id/buckysInput"
  295. android:layout_alignStart="@+id/buckysInput" />
  296.  
  297. <EditText
  298. android:layout_width="wrap_content"
  299. android:layout_height="wrap_content"
  300. android:id="@+id/numRides"
  301. android:width="250dp"
  302. android:hint="Number of Rides"
  303. android:layout_below="@+id/ppr"
  304. android:layout_alignStart="@+id/ppr"
  305. android:layout_marginTop="30dp" />
  306.  
  307. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement