Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. String choosenItem = "nothing";
  4. Connection connect;
  5. PreparedStatement preparedStatement;
  6. Statement st;
  7. String[] list;
  8. List<String> ArrayListing =new ArrayList<String>();
  9.  
  10. @SuppressLint("NewApi")
  11. private Connection ConnectionHelper() {
  12. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  13. .permitAll().build();
  14. StrictMode.setThreadPolicy(policy);
  15. Connection connection = null;
  16. String ConnectionURL = null;
  17. try {
  18. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  19. Log.e("ERRO", "Class Loaded");
  20. ConnectionURL = "jdbc:jtds:sqlserver://localhost/portal;encrypt=fasle;user=cp_t;password=cp3;instance=MSSQLSERVER;";
  21. connection = DriverManager.getConnection(ConnectionURL);
  22. Log.e("ERRO", "Connection Established");
  23. } catch (SQLException se) {
  24. Log.e("ERRO", se.getMessage());
  25. } catch (ClassNotFoundException e) {
  26. Log.e("ERRO", e.getMessage());
  27. } catch (Exception e) {
  28. Log.e("ERRO", e.getMessage());
  29. }
  30. return connection;
  31. }
  32.  
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_main);
  38.  
  39. Runnable r = new Runnable() {
  40. @Override
  41. public void run() {
  42. try {
  43. connect = ConnectionHelper();
  44.  
  45. st = connect.createStatement();
  46. ResultSet rs = st.executeQuery("select Items from drop_down");
  47. Log.d("ERRO", "Result set executed");
  48. Array z = null;
  49. String s;
  50. while(rs.next()){
  51.  
  52. s = rs.getString(1);
  53. Log.d("Database Strings", s);
  54.  
  55. ArrayListing.add(s);
  56. Log.d("Feeding array", "did it");
  57. //z = rs.getArray("Items");
  58. }
  59.  
  60. //list = (String[])z.getArray();
  61.  
  62. } catch (SQLException e) {
  63. Log.e("ERRO", "Runnable Error");
  64. e.printStackTrace();
  65. }
  66. }
  67. };
  68.  
  69. Thread t = new Thread(r);
  70. t.start();
  71.  
  72. Spinner dynamicSpinner = (Spinner) findViewById(R.id.dynamic_spinner);
  73.  
  74. String[] items = ArrayListing.toArray(new String[ArrayListing.size()]);
  75.  
  76. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  77. android.R.layout.simple_spinner_item, ArrayListing);
  78.  
  79. dynamicSpinner.setAdapter(adapter);
  80.  
  81. dynamicSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  82. @Override
  83. public void onItemSelected(AdapterView<?> parent, View view,
  84. int position, long id) {
  85.  
  86. choosenItem = (String) parent.getItemAtPosition(position);
  87. Log.v("item", choosenItem);
  88. TextView show = (TextView) findViewById(R.id.show);
  89.  
  90. show.setText(choosenItem);
  91. }
  92.  
  93. @Override
  94. public void onNothingSelected(AdapterView<?> parent) {
  95. // TODO Auto-generated method stub
  96. }
  97. });
  98.  
  99.  
  100. }
  101. }
  102.  
  103. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  104. xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  105. android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  106. android:paddingRight="@dimen/activity_horizontal_margin"
  107. android:paddingTop="@dimen/activity_vertical_margin"
  108. android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
  109.  
  110. <Spinner
  111. android:id="@+id/dynamic_spinner"
  112. android:layout_width="fill_parent"
  113. android:layout_height="wrap_content" />
  114.  
  115. <TextView
  116. android:layout_width="wrap_content"
  117. android:layout_height="wrap_content"
  118. android:text="HERE"
  119. android:layout_alignParentBottom="true"
  120. android:layout_centerHorizontal="true"
  121. android:layout_marginBottom="34dp"
  122. android:id="@+id/show" />
  123.  
  124. </RelativeLayout>
  125.  
  126. 09-06 11:03:38.929 2369-2385/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  127. 09-06 11:03:38.929 2369-2385/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa67d7340, error=EGL_SUCCESS
  128. 09-06 11:03:39.028 1223-1253/? I/ActivityManager﹕ Displayed com.muchmore.www.dropdown/.MainActivity: +430ms
  129. 09-06 11:03:45.202 2369-2384/? E/ERRO﹕ Connection Established
  130. 09-06 11:03:45.277 2369-2384/? D/ERRO﹕ Result set executed
  131. 09-06 11:03:45.277 2369-2384/? D/Database Strings﹕ Ground
  132. 09-06 11:03:45.277 2369-2384/? D/Feeding array﹕ did it
  133. 09-06 11:03:45.277 2369-2384/? D/Database Strings﹕ Classes
  134. 09-06 11:03:45.277 2369-2384/? D/Feeding array﹕ did it
  135. 09-06 11:03:45.278 2369-2384/? D/Database Strings﹕ Labs
  136. 09-06 11:03:45.278 2369-2384/? D/Feeding array﹕ did it
  137. 09-06 11:03:45.278 2369-2384/? D/Database Strings﹕ Buildings
  138. 09-06 11:03:45.278 2369-2384/? D/Feeding array﹕ did it
  139. 09-06 11:03:45.278 2369-2384/? D/Database Strings﹕ Libraries
  140. 09-06 11:03:45.278 2369-2384/? D/Feeding array﹕ did it
  141. 09-06 11:03:52.439 2369-2369/? W/art﹕ Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
  142. 09-06 11:03:52.486 2369-2385/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  143. 09-06 11:03:52.486 2369-2385/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa644a0a0, error=EGL_SUCCESS
  144. 09-06 11:03:54.452 1223-1277/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
  145. 09-06 11:03:54.473 2369-2369/? W/InputEventReceiver﹕ Attempted to finish an input event but the input event receiver has already been disposed.
  146. 09-06 11:03:54.478 1223-1237/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2d9ab1ee attribute=null, token = android.os.BinderProxy@12992f4a
  147. 09-06 11:03:56.631 2369-2385/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  148. 09-06 11:03:56.631 2369-2385/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa64e9500, error=EGL_SUCCESS
  149. 09-06 11:03:57.388 1223-1277/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
  150. 09-06 11:03:57.396 2369-2369/? W/InputEventReceiver﹕ Attempted to finish an input event but the input event receiver has already been disposed.
  151. 09-06 11:03:57.399 1223-1514/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2144bd25 attribute=null, token = android.os.BinderProxy@12992f4a
  152.  
  153. @Override
  154. public void onItemSelected(AdapterView<?> parent, View view,
  155. int position, long id) {
  156. choosenItem = dynamicSpinner.getItemAtPosition(position).toString();
  157. Log.v("item", choosenItem);
  158. TextView show = (TextView) findViewById(R.id.show);
  159. show.setText(choosenItem);
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement