1. Are you ready for the Galaxy S20? Here is everything we know so far!

Need help switching screens in gridlayout

Discussion in 'Android Apps & Games' started by newageapper201, Jul 18, 2013.

  1. newageapper201

    Thread Starter

    Hello fellow app developers! I need assistance with an app I'm developing. I am trying to program the app so that when you click a grid, it switches to its respective screen. I've posted the code below in the activity, so you can tell me what I'm doing wrong. Please don't hesitate to request further code to see the problem in full detail.


    Code (Text):
    1. public class FullImageActivity extends Activity {
    2.  
    3.     @Override
    4.     public void onCreate(Bundle savedInstanceState) {
    5.        
    6.        
    7.           // get intent data
    8.         Intent i = getIntent();
    9.  
    10.         // Selected image id
    11.         int position = i.getExtras().getInt("id");
    12.      // based on array position switches to its respective screen
    13.         switch (position)
    14.         {
    15.        case 6:
    16.            super.onCreate(savedInstanceState);
    17.            setContentView(R.layout.page1);
    18.            break;
    19.      
    20.            case 0:
    21.            super.onCreate(savedInstanceState);
    22.            setContentView(R.layout.page2);
    23.            break;
    24.        
    25.           case 1:
    26.            super.onCreate(savedInstanceState);
    27.            setContentView(R.layout.page3);
    28.            break;
    29.      
    30.            case 2:
    31.            super.onCreate(savedInstanceState);
    32.            setContentView(R.layout.page4);
    33.            break;
    34.      
    35.            case 3:
    36.            super.onCreate(savedInstanceState);
    37.            setContentView(R.layout.page5);
    38.            break;
    39.          
    40.            case 4:
    41.            super.onCreate(savedInstanceState);
    42.            setContentView(R.layout.page6);
    43.            break;
    44.      
    45.            case 7:
    46.            super.onCreate(savedInstanceState);
    47.            setContentView(R.layout.page7);
    48.            break;
    49.         }
    50.        
    51.        
    52.  
    53.     }
    54.  
    55. }
    56.  
     

    Advertisement

Loading...

Share This Page

Loading...