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.