I can not configure the second activation to extract data from the first activation

It is necessary in the second activation to extract the corresponding text from:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: Intent intent = new Intent(MainActivity.this, about.class); intent.putExtra("key1", R.string.tekst1); startActivity(intent); case 1: Intent intent1 = new Intent(MainActivity.this, about.class); intent2.putExtra("key1", R.string.tekst2); startActivity(intent1); case 2: Intent intent2 = new Intent(MainActivity.this, about.class); inten2t.putExtra("key1", R.string.tekst3); startActivity(intent2); } } }); 

how to extract them help

  • And how do you extract data? Note that R.string.tekst1 is a number (of type int ). By the way, you in switch lost all break . - s8am
  • Does off.documentation describe this process in sufficient detail? Then what is the problem with the extraction and where is the extraction itself in the second activation? According to the existing code, you can only suggest to startActivity() outside the switch-case block, and creating an Intent instance before the switch-case block in order to optimize the reduction of duplicate code. - pavlofff
  • one
    the different names of the variables being created and the variables that Extra is added to are just a typo, I guess? in general, yes, it would be nice to see how the extraction takes place - Fitz

1 answer 1

 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, about.class); switch (position) { case 0: intent.putExtra("key1", getResource().getString(R.string.tekst1)); break; case 1: intent.putExtra("key1", getResource().getString(R.string.tekst2)); break ; case 2: intent.putExtra("key1", getResource ().getString(R.string.tekst3)); break ; } startActivity (intent) ; } }); 
  • thank you andboooooooo !!!!!!! - elik