IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

Passage d'un layout portait / paysage avec des fragment intégré dynamiquement


Sujet :

Composants graphiques Android

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Points : 9
    Points
    9
    Par défaut Passage d'un layout portait / paysage avec des fragment intégré dynamiquement
    Bonjour,

    je me confronte à un obstacle voilà je cherche à faire en sorte que dès qu'on change l'orientation l'activité prennent le layout qui lui correspond mais je ne vois pas trop comment procédé

    j'ai pour le moment fait ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    @Override
        public void onConfigurationChanged(Configuration newConfig){
            super.onConfigurationChanged(newConfig);
     
            if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
                setContentView(R.layout.activity_login);
                Log.v("test","LANDSCAPE");
            }else{
                setContentView(R.layout.activity_login);
                Log.v("test","PORTRAIT");
            }
        }
    et ajouté ça au manifest
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    android:configChanges="keyboardHidden|orientation|screenSize"
    Mais bien sur il m'affiche le bon layout mais je ne vois pas comment faire pour que mes fragments s'adapte et s'affiche :/


    edit : ça plante même direct si je suis en landscape j'ai cet erreur

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gyp.gyp/com.example.gyp.gyp.LoginActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f07003c (com.example.gyp.gyp:id/fragment_login_container) for fragment LoaderPageFragment{4254b1a0 #0 id=0x7f07003c}


    Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f07003c (com.example.gyp.gyp:id/fragment_login_container) for fragment LoaderPageFragment{4254b1a0 #0 id=0x7f07003c}
    edit2 : mon appli ce décompose de la façon suivant j'ai un fragmentactivity dans lequel je fais appel à plusieurs fragment mais aussi un autres fragment activity qui lui aussi à d'autres fragments

    si ça peut aider ^^

  2. #2
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut
    ton layout dois exister dans layout-land et layout-sw600dp-land mode tablet


    voila un exemple
    res/layout-land/fragment_layout.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:orientation="horizontal" >
     
        <fragment
            android:id="@+id/titles"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            class="edu.dartmouth.cs.FragmentLayout$TitlesFragment" />
     
        <FrameLayout
            android:id="@+id/details"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="?android:attr/detailsElementBackground" />
     
    </LinearLayout>

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
     
    public class FragmentLayout extends Activity {
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
     
    		Toast.makeText(this, "FragmentLayout: OnCreate()", Toast.LENGTH_SHORT)
    				.show();
     
    		// Sets the view. Depending on orientation it will select either
    		// res/layout/fragment_layout.xml (portrait mode) or
    		// res/layout-land/fragment_layout.xml (landscape mode). This is done
    		// automatically by the system.
    		setContentView(R.layout.fragment_layout);
    	}
     
    	// This is a secondary activity, to show what the user has selected when the
    	// screen is not large enough to show it all in one activity.
     
    	public static class DetailsActivity extends Activity {
     
    		@Override
    		protected void onCreate(Bundle savedInstanceState) {
    			super.onCreate(savedInstanceState);
     
    			Toast.makeText(this, "DetailsActivity", Toast.LENGTH_SHORT).show();
     
    			if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
    				// If the screen is now in landscape mode, we can show the
    				// dialog in-line with the list so we don't need this activity.
    				finish();
    				return;
    			}
     
    			if (savedInstanceState == null) {
    				// During initial setup, plug in the details fragment.
     
    				// create fragment
    				DetailsFragment details = new DetailsFragment();
     
    				// get and set the position input by user (i.e., "index")
    				// which is the construction arguments for this fragment
    				details.setArguments(getIntent().getExtras());
     
    				//
    				getFragmentManager().beginTransaction()
    						.add(android.R.id.content, details).commit();
    			}
    		}
    	}
     
    	// This is the "top-level" fragment, showing a list of items that the user
    	// can pick. Upon picking an item, it takes care of displaying the data to
    	// the user as appropriate based on the current UI layout.
     
    	// Displays a list of items that are managed by an adapter similar to
    	// ListActivity. It provides several methods for managing a list view, such
    	// as the onListItemClick() callback to handle click events.
     
    	public static class TitlesFragment extends ListFragment {
    		boolean mDualPane;
    		int mCurCheckPosition = 0;
     
    		// onActivityCreated() is called when the activity's onCreate() method
    		// has returned.
     
    		@Override
    		public void onActivityCreated(Bundle savedInstanceState) {
    			super.onActivityCreated(savedInstanceState);
     
    			// You can use getActivity(), which returns the activity associated
    			// with a fragment.
    			// The activity is a context (since Activity extends Context) .
     
    			Toast.makeText(getActivity(), "TitlesFragment:onActivityCreated",
    					Toast.LENGTH_LONG).show();
     
    			// Populate list with our static array of titles in list in the
    			// Shakespeare class
    			setListAdapter(new ArrayAdapter<String>(getActivity(),
    					android.R.layout.simple_list_item_activated_1,
    					Shakespeare.TITLES));
     
    			// Check to see if we have a frame in which to embed the details
    			// fragment directly in the containing UI.
    			// R.id.details relates to the res/layout-land/fragment_layout.xml
    			// This is first created when the phone is switched to landscape
    			// mode
     
    			View detailsFrame = getActivity().findViewById(R.id.details);
     
    			Toast.makeText(getActivity(), "detailsFrame " + detailsFrame,
    					Toast.LENGTH_LONG).show();
     
    			// Check that a view exists and is visible
    			// A view is visible (0) on the screen; the default value.
    			// It can also be invisible and hidden, as if the view had not been
    			// added.
    			//
    			mDualPane = detailsFrame != null
    					&& detailsFrame.getVisibility() == View.VISIBLE;
     
    			Toast.makeText(getActivity(), "mDualPane " + mDualPane,
    					Toast.LENGTH_LONG).show();
     
    			if (savedInstanceState != null) {
    				// Restore last state for checked position.
    				mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
    			}
     
    			if (mDualPane) {
    				// In dual-pane mode, the list view highlights the selected
    				// item.
    				getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    				// Make sure our UI is in the correct state.
    				showDetails(mCurCheckPosition);
    			} else {
    				// We also highlight in uni-pane just for fun
    				getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    				getListView().setItemChecked(mCurCheckPosition, true);
    			}
    		}
     
    		@Override
    		public void onSaveInstanceState(Bundle outState) {
    			super.onSaveInstanceState(outState);
    			Toast.makeText(getActivity(), "onSaveInstanceState",
    					Toast.LENGTH_LONG).show();
     
    			outState.putInt("curChoice", mCurCheckPosition);
    		}
     
    		// If the user clicks on an item in the list (e.g., Henry V then the
    		// onListItemClick() method is called. It calls a helper function in
    		// this case.
     
    		@Override
    		public void onListItemClick(ListView l, View v, int position, long id) {
     
    			Toast.makeText(getActivity(),
    					"onListItemClick position is" + position, Toast.LENGTH_LONG)
    					.show();
     
    			showDetails(position);
    		}
     
    		// Helper function to show the details of a selected item, either by
    		// displaying a fragment in-place in the current UI, or starting a whole
    		// new activity in which it is displayed.
     
    		void showDetails(int index) {
    			mCurCheckPosition = index;
     
    			// The basic design is mutli-pane (landscape on the phone) allows us
    			// to display both fragments (titles and details) with in the same
    			// activity; that is FragmentLayout -- one activity with two
    			// fragments.
    			// Else, it's single-pane (portrait on the phone) and we fire
    			// another activity to render the details fragment - two activities
    			// each with its own fragment .
    			//
    			if (mDualPane) {
    				// We can display everything in-place with fragments, so update
    				// the list to highlight the selected item and show the data.
    				// We keep highlighted the current selection
    				getListView().setItemChecked(index, true);
     
    				// Check what fragment is currently shown, replace if needed.
    				DetailsFragment details = (DetailsFragment) getFragmentManager()
    						.findFragmentById(R.id.details);
    				if (details == null || details.getShownIndex() != index) {
    					// Make new fragment to show this selection.
     
    					details = DetailsFragment.newInstance(index);
     
    					Toast.makeText(getActivity(),
    							"showDetails dual-pane: create and relplace fragment",
    							Toast.LENGTH_LONG).show();
     
    					// Execute a transaction, replacing any existing fragment
    					// with this one inside the frame.
    					FragmentTransaction ft = getFragmentManager()
    							.beginTransaction();
    					ft.replace(R.id.details, details);
    					ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    					ft.commit();
    				}
     
    			} else {
    				// Otherwise we need to launch a new activity to display
    				// the dialog fragment with selected text.
    				// That is: if this is a single-pane (e.g., portrait mode on a
    				// phone) then fire DetailsActivity to display the details
    				// fragment
     
    				// Create an intent for starting the DetailsActivity
    				Intent intent = new Intent();
     
    				// explicitly set the activity context and class
    				// associated with the intent (context, class)
    				intent.setClass(getActivity(), DetailsActivity.class);
     
    				// pass the current position
    				intent.putExtra("index", index);
     
    				startActivity(intent);
    			}
    		}
    	}
     
    	// This is the secondary fragment, displaying the details of a particular
    	// item.
     
    	public static class DetailsFragment extends Fragment {
     
    		// Create a new instance of DetailsFragment, initialized to show the
    		// text at 'index'.
     
    		public static DetailsFragment newInstance(int index) {
    			DetailsFragment f = new DetailsFragment();
     
    			// Supply index input as an argument.
    			Bundle args = new Bundle();
    			args.putInt("index", index);
    			f.setArguments(args);
     
    			return f;	
    		}
     
    		public int getShownIndex() {
    			return getArguments().getInt("index", 0);
    		}
     
    		// The system calls this when it's time for the fragment to draw its
    		// user interface for the first time. To draw a UI for your fragment,
    		// you must return a View from this method that is the root of your
    		// fragment's layout. You can return null if the fragment does not
    		// provide a UI.
     
    		// We create the UI with a scrollview and text and return a reference to
    		// the scoller which is then drawn to the screen
     
    		@Override
    		public View onCreateView(LayoutInflater inflater, ViewGroup container,
    				Bundle savedInstanceState) {
     
    			Toast.makeText(getActivity(), "DetailsFragment:onCreateView",
    					Toast.LENGTH_LONG).show();
    			//
    			// if (container == null) {
    			// // We have different layouts, and in one of them this
    			// // fragment's containing frame doesn't exist. The fragment
    			// // may still be created from its saved state, but there is
    			// // no reason to try to create its view hierarchy because it
    			// // won't be displayed. Note this is not needed -- we could
    			// // just run the code below, where we would create and return
    			// // the view hierarchy; it would just never be used.
    			// return null;
    			// }
     
    			// If non-null, this is the parent view that the fragment's UI
    			// should be attached to. The fragment should not add the view
    			// itself, but this can be used to generate the LayoutParams of
    			// the view.
    			//
     
    			// programmatically create a scrollview and texview for the text in
    			// the container/fragment layout. Set up the properties and add the
    			// view.
     
    			ScrollView scroller = new ScrollView(getActivity());
    			TextView text = new TextView(getActivity());
    			int padding = (int) TypedValue.applyDimension(
    					TypedValue.COMPLEX_UNIT_DIP, 4, getActivity()
    							.getResources().getDisplayMetrics());
    			text.setPadding(padding, padding, padding, padding);
    			scroller.addView(text);
    			text.setText(Shakespeare.DIALOGUE[getShownIndex()]);
    			return scroller;
    		}
    	}
     
    }

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Points : 9
    Points
    9
    Par défaut
    merci ça ne plante plus et ça affiche bien le layout qu'il faut quand il démarre maintenant je vais voir pour le changer quand on change l'orientation

    edit : bon alors je sais pas si ce que j'ai fait est bon mais bon ça a l'air de marcher

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
        @Override
        public void onConfigurationChanged(Configuration newConfig){
            super.onConfigurationChanged(newConfig);
     
     
                fragmentTransaction = fm.beginTransaction();
                fragmentTransaction.remove(getSupportFragmentManager()
                        .findFragmentById(R.id.fragment_login_container))
                        .add(R.id.fragment_login_container, frag).commit();
     
     
        }
    Vous en pensez quoi?

  4. #4
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut
    je crois que tu dois faire un test d orientation avec une condition dans ta method onConfigurationChanged

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
     
        Log.e("On Config Change","LANDSCAPE");
    }else{
     
        Log.e("On Config Change","PORTRAIT");
    }

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Points : 9
    Points
    9
    Par défaut
    j'ai testé avec et sans pas de soucis ca évite d'avoir 2 fois le même code au final nop?

  6. #6
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut
    tout depant de ta FANTASIE JAVA

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Points : 9
    Points
    9
    Par défaut
    On va dire que java j'ai très peu pratiqué mise a part avec android ^^

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Template de projet avec des fichiers ajoutés dynamiquement
    Par Benzeghiba dans le forum Visual Studio
    Réponses: 1
    Dernier message: 23/06/2008, 21h50
  2. une page jsp avec des controles graphique dynamiques
    Par capello123 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 14/12/2007, 16h37
  3. Réponses: 4
    Dernier message: 03/07/2007, 09h42
  4. Tables avec des relations & procédures dynamiques
    Par JustMe dans le forum Débuter
    Réponses: 5
    Dernier message: 15/12/2004, 09h58
  5. Erreur EACCESSVIOLATION avec des compsts créés dynamiquement
    Par tsikpemoise dans le forum Bases de données
    Réponses: 4
    Dernier message: 28/02/2004, 19h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo