There is 2 Activity, I want from the first Activity listView via intent to transfer to 2 Activity implemented the data by this method:

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("ke2", getResource().getString(R.string.tekst2)); break ; case 2: intent.putExtra("key3", getResource ().getString(R.string.tekst3)); break ; } startActivity (intent) ; } }); 

And here is how I tried to extract in the second one

 TextView textView = (TextView) findbyiD(R.id.textview); String tekst =getIntent().getExtras().getString("key1"); switch(i){ case 0: TextView.setText(key1) case1: break; textview.setText(key2) case2: break; texView.setTex(key3) break; 

    2 answers 2

    Try this:

     Intent intent = getIntent(); Bundle extras = intent.getExtras(); String text = extras.getString("key1"); 

    or so:

     switch(i) { case 0: TextView.setText(extras.getString("key1")) break; case1: textview.setText(extras.getString("key2")) break; case2: texView.setTex(extras.getString("key3")) break; } 
    • switch i turns red - elik
    • well you decide what i . I assume that this is a position in the onItemClick method in the first Activity. If so, you can pass through the intent and its value. And then equate this value of the variable i - Marat
    • Yes, this is exactly position and how to pass it through intent &&& ???? I will be very blogging - elik

    Your question is similar to this.

    You are not looking for your extras. You put it right in the Intent, and you are looking for it in the internal Bundle Intent-a.

    Those. you need to pull out something like this:

     String tekst = getIntent().getStringExtra("key1", "error"); 
    • Slea failed (something was wrong - elik
    • I'd rather not find a case for a position error where swtich - elik
    • @elik, well, you have there, in the second activity, some kind of confusion with break - YuriySPb
    • Please help me more precisely, first show how to extract ut extra and then help with the condition for the button which was pressed - elik