Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Lista1 extends AppCompatActivity implements AdapterView.OnItemClickListener {
- ListView lista;
- RelativeLayout screen;
- String[] temp;
- String[] tabload;
- ArrayList<String> list;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_lista1);
- screen = (RelativeLayout) findViewById(R.id.lista1);
- loadAll();
- }
- public void loadData() {
- BufferedReader input = null;
- StringBuffer buffer = null;
- String wynik = "";
- File dir = new File(getExternalFilesDir(null), "Data.txt");
- try {
- FileInputStream fis = new FileInputStream(dir);
- InputStreamReader isr = new InputStreamReader(fis);
- BufferedReader br = new BufferedReader(isr);
- String line;
- buffer = new StringBuffer();
- while ((line = br.readLine()) != null) {
- wynik = wynik + line + " ";
- }
- String delims = "[ ]+";
- String[] tab2 = wynik.split(delims);
- tabload = new String[tab2.length];
- for (int i = 0; i < tab2.length; i++) {
- tabload[i] = tab2[i];
- }
- temp = new String[((tab2.length) / 7) * 2];
- int j = 0;
- int ilosc = (tab2.length) / 7;
- for (int i = 0; i < ilosc; i++) {
- temp[j] = tab2[0 + (i * 7)];
- temp[j + 1] = tab2[1 + (i * 7)];
- j = j + 2;
- }
- int k = 0;
- for (int i = 0; i < ilosc; i++) {
- if (!list.contains(temp[k] + " " + temp[k + 1])) {
- list.add(temp[k] + " " + temp[k + 1]);
- }
- k = k + 2;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- int ilosc = list.size();
- String gra = "";
- String rok = "";
- String czas = "";
- String platna = "";
- for (int i = 0; i < ilosc; i++) {
- if (position == i) {
- gra = tabload[i * 7];
- rok = tabload[(i * 7) + 1];
- czas = tabload[(i * 7) + 2];
- platna = tabload[(i * 7) + 3];
- }
- }
- Bundle dane = new Bundle();
- dane.putString("Gra", gra);
- dane.putString("Rok", rok);
- dane.putString("Czas", czas);
- dane.putString("Oplata", platna);
- final Intent intencja = new Intent(this, Szczegoly.class);
- intencja.putExtras(dane);
- startActivityForResult(intencja, 123);
- }
- protected void onResume() {
- super.onResume();
- SharedPreferences odbierz = getSharedPreferences("MyPreferences", MODE_PRIVATE);
- int color = odbierz.getInt("Background", -1);
- screen.setBackgroundColor(color);
- }
- public void loadAll() {
- list = new ArrayList<>();
- loadData();
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
- lista = (ListView) findViewById(R.id.listView);
- lista.setOnItemClickListener(this);
- lista.setAdapter(adapter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement