Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. public class Lista1 extends AppCompatActivity implements AdapterView.OnItemClickListener {
  2.  
  3. ListView lista;
  4. RelativeLayout screen;
  5.  
  6. String[] temp;
  7. String[] tabload;
  8. ArrayList<String> list;
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_lista1);
  14. screen = (RelativeLayout) findViewById(R.id.lista1);
  15. loadAll();
  16.  
  17. }
  18.  
  19. public void loadData() {
  20. BufferedReader input = null;
  21. StringBuffer buffer = null;
  22. String wynik = "";
  23. File dir = new File(getExternalFilesDir(null), "Data.txt");
  24. try {
  25. FileInputStream fis = new FileInputStream(dir);
  26. InputStreamReader isr = new InputStreamReader(fis);
  27. BufferedReader br = new BufferedReader(isr);
  28. String line;
  29. buffer = new StringBuffer();
  30.  
  31. while ((line = br.readLine()) != null) {
  32. wynik = wynik + line + " ";
  33. }
  34. String delims = "[ ]+";
  35. String[] tab2 = wynik.split(delims);
  36. tabload = new String[tab2.length];
  37. for (int i = 0; i < tab2.length; i++) {
  38. tabload[i] = tab2[i];
  39. }
  40. temp = new String[((tab2.length) / 7) * 2];
  41. int j = 0;
  42. int ilosc = (tab2.length) / 7;
  43.  
  44. for (int i = 0; i < ilosc; i++) {
  45. temp[j] = tab2[0 + (i * 7)];
  46. temp[j + 1] = tab2[1 + (i * 7)];
  47. j = j + 2;
  48. }
  49. int k = 0;
  50. for (int i = 0; i < ilosc; i++) {
  51. if (!list.contains(temp[k] + " " + temp[k + 1])) {
  52. list.add(temp[k] + " " + temp[k + 1]);
  53. }
  54. k = k + 2;
  55. }
  56.  
  57. } catch (FileNotFoundException e) {
  58. e.printStackTrace();
  59. } catch (IOException e) {
  60. e.printStackTrace();
  61. }
  62. }
  63.  
  64.  
  65. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  66. int ilosc = list.size();
  67. String gra = "";
  68. String rok = "";
  69. String czas = "";
  70. String platna = "";
  71. for (int i = 0; i < ilosc; i++) {
  72. if (position == i) {
  73. gra = tabload[i * 7];
  74. rok = tabload[(i * 7) + 1];
  75. czas = tabload[(i * 7) + 2];
  76. platna = tabload[(i * 7) + 3];
  77. }
  78. }
  79. Bundle dane = new Bundle();
  80. dane.putString("Gra", gra);
  81. dane.putString("Rok", rok);
  82. dane.putString("Czas", czas);
  83. dane.putString("Oplata", platna);
  84. final Intent intencja = new Intent(this, Szczegoly.class);
  85. intencja.putExtras(dane);
  86. startActivityForResult(intencja, 123);
  87.  
  88. }
  89.  
  90. protected void onResume() {
  91. super.onResume();
  92. SharedPreferences odbierz = getSharedPreferences("MyPreferences", MODE_PRIVATE);
  93. int color = odbierz.getInt("Background", -1);
  94. screen.setBackgroundColor(color);
  95. }
  96.  
  97. public void loadAll() {
  98. list = new ArrayList<>();
  99. loadData();
  100.  
  101. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
  102. lista = (ListView) findViewById(R.id.listView);
  103. lista.setOnItemClickListener(this);
  104. lista.setAdapter(adapter);
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement