Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Lets say, I have a list view which contains questions. When you click one of them you will see the answer o another page. This means lots of activity class. Then I am looking for another solution.</p> </blockquote> <p>No, you don't need different activities for this. You can make your "Answer activity" dynamic. It can change data according to which ListView item was clicked. Here's a simple solution to your problem. Create a new int variable and change it accordingly to which ListView item was clicked. If item at index 0 was clicked, then this int should be 0. Pass it with extras to your answer activity and in your answer activity, implement an IF statement.</p> <pre><code>if (intVariable == 0) { //show answer 0 } else if (intVariable == 1) { //show answer 1 } </code></pre> <p>Do you get the concept?</p> <p>So, if you want to change the layout accordingly to which ListView item was clicked, this might help you.</p> <p>Are you changing only image sources or actual layout positions? If you're changing positions, you might aswell create another activity because changing layout positions programatically would take too much time and it's too complicated.</p> <p>Do you only want image sources to change but layout positions to stay the same? Then this is easier. This code might help you:</p> <pre><code>int position = //get int extras here switch (position) case 0: imageView1.setImageResources(r.id.yourPicture); case 1: imageView1.setImageResources(r.id.yourPic2); </code></pre> <p>So as you can see, your image resource changed accordingly to ListView item clicked.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload