It is very difficult to explain and anticipate curses, I apologize in advance. When I have the first array (numbers) list on the screen and I click on the first one from the list and the first one from the second list appears on the screen array (letters) I need that when I'm in the second list (letters) and I move my finger down the screen ( swipe) I got the following in order from the second list (letters). Here is the code I wrote
Two activites:

1st:

public class MainActivity extends AppCompatActivity { ListView listView; ArrayList<String> numbers; ArrayList<String> letters; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_words); listView = (ListView) findViewById(R.id.listView); numbers = new ArrayList<>(); numbers.add("1"); numbers.add("2"); numbers.add("3"); numbers.add("4"); numbers.add("5"); numbers.add("6"); letters = new ArrayList<>(); letters.add("a"); letters.add("b"); letters.add("c"); letters.add("d"); letters.add("e"); letters.add("f"); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.activity_main, numbers); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String secListItem = letters.get(position); SharedPreferences settings = getSharedPreferences("PREFS", 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("letters", secListItem ); editor.apply(); Intent intent = new Intent(getApplicationContext(), ScreenActivity.class); startActivity(intent); } }); } } 

2nd:

 public class ScreenActivity extends AppCompatActivity { TextView textView; String letters; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen); textView = (TextView) findViewById(R.id.textView); SharedPreferences settings = getSharedPreferences("PREFS", 0); letters = settings.getString("letters", ""); textView.setText(letters); } } 
  • it is exactly one letter that should ideally need to have a list with numbers, and when I click on the first one, it’s the first one, but it’s supposed to be separate from everyone, and when I move my finger down on the screen, I will go back to the next one I simplified the list (number 2) here in the code so that it would be clearer to make a separate activation for each letter of course, but probably this is not correct, there is just a very large array list planned - Vladimir Gusev
  • yes everything is correct - Vladimir Gusev
  • How to note what is answered? I do not know how ( - Vladimir Gusev
  • I apologize, did not immediately find what needs to be done, thanks again) - Vladimir Gusev

1 answer 1

You can do something like this. In the first activation, we display a list with numbers and determine the position on which we clicked. This position is passed to the next activity through the intent to display the corresponding letter:

 public class MainActivity extends AppCompatActivity { ListView listView; ArrayList<String> numbers; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_words); listView = (ListView) findViewById(R.id.listView); numbers = new ArrayList<>(); numbers.add("1"); numbers.add("2"); numbers.add("3"); numbers.add("4"); numbers.add("5"); numbers.add("6"); ArrayAdapter<String> adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, numbers); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Intent intent = new Intent(getApplicationContext(), ScreenActivity.class); intent.putExtra("position", position); startActivity(intent); } }); } } 

In the second activation, we obtain the desired position from the intent and output the corresponding letter. In order to be able to scroll through them, we add a gesture listener to the widget, which will process the motion, changing the letter accordingly:

 public class ScreenActivity extends AppCompatActivity { private static final int SWIPE_MIN_DISTANCE = 50; private static final int SWIPE_THRESHOLD_VELOCITY = 50; TextView textView; LinearLayout container; int positionX = 0; int positionY; List<List<String>> letters; GestureDetectorCompat gdt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen); // списки "ΠΏΠΎ Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΠΈ" letters = new ArrayList<>(); // Бписки "ΠΏΠΎ Π³ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΠΈ" ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.add("A"); a.add("A1"); a.add("A2"); b.add("B"); b.add("B1"); b.add("B2"); b.add("B3"); letters.add(a); letters.add(b); // Π”ΠΎΠ±Π°Π²ΠΈΠΌ Π½ΠΎΠ²Ρ‹ΠΉ "столбСц" ArrayList c = new ArrayList(); // Π”ΠΎΠ±Π°Π²ΠΈΠΌ элСмСнт Π² "строку" Π½ΠΎΠ²ΠΎΠ³ΠΎ "столбца" c.add("C"); letters.add(c); // Π”ΠΎΠ±Π°Π²ΠΈΠΌ Π½ΠΎΠ²Ρ‹ΠΉ элСмСнт Π² "строку" с символом B b.add("B4"); positionY = getIntent().getIntExtra("position", 0); gdt = new GestureDetectorCompat(this, new GestureListener()); textView = (TextView) findViewById(R.id.textView); container = (LinearLayout) findViewById(R.id.container); updateUI(); container.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { gdt.onTouchEvent(event); return true; } }); } private void updateUI() { if (positionY < 0) positionY = 0; if (positionY > (letters.size() - 1)) positionY = letters.size() - 1; ArrayList<String> x = (ArrayList) letters.get(positionY); if (positionX < 0) positionX = 0; if (positionX > (x.size() - 1)) positionX = x.size() - 1; textView.setText(x.get(positionX)); } private class GestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // справа Π½Π°Π»Π΅Π²ΠΎ positionX++; updateUI(); return false; } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // слСва Π½Π°ΠΏΡ€Π°Π²ΠΎ positionX--; updateUI(); return false; } if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { // Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ Π²Π²Π΅Ρ€Ρ… positionY++; positionX = 0; // Π² Π½Π°Ρ‡Π°Π»ΠΎ строки updateUI(); return false; } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { // Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ Π²Π½ΠΈΠ· positionY--; positionX = 0; // Π² Π½Π°Ρ‡Π°Π»ΠΎ стоки updateUI(); return false; } return false; } } } 

container is the area that will respond to the gesture with your finger, in this case LinearLayout , in which the TextView is located. This area of ​​response can be larger than the widget itself, in which letters are displayed.

  • Thanks, everything works fine) And if I create the third Array and when I swipe the letters on the page with letters to the right, I moved to the third array in a position just like me to implement it? I tried to do it according to your sample, but somehow it does not work out in position and if I do the swipe right again, then it is still not clear where it goes to the third array, but I need it to stop. - Vladimir Gusev
  • let's say the third array is both numbers and letters and in order will be 1a, 2b and so on. those. I need if I opened A and do the svayp to the right, it should open 1A, but it opens 2B and if there is still a svayp to the right, it will be 3C. And if I do a svayp down with 1A, then, in theory, A should open, but it opens as much as 3, so they have order just in turn - Vladimir Gusev
  • yes B I just need to add, or can I just do a limited number there? then, in principle, you can really do not know what it is - Vladimir Gusev
  • thank you very much! everything works) did not even hope that it would work out, but you did it - Vladimir Gusev