LAb 4 fertifg
This commit is contained in:
parent
2105cb8303
commit
8dd46f941c
|
@ -1,6 +1,8 @@
|
|||
package at.fhj.airkoality.ui.activity;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
|
@ -21,10 +23,13 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
private static final String LOCATION_LIST = "location_list";
|
||||
private static final String MAP = "map";
|
||||
private static final String FRAGMENT_PREF_KEY = "last_fragment";
|
||||
|
||||
|
||||
private BottomNavigationView bottomNavigationView;
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -36,6 +41,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
bottomNavigationView = findViewById(R.id.bnvMain);
|
||||
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.add(R.id.flFragmentContainer, locationListFragment);
|
||||
transaction.add(R.id.flFragmentContainer, mapFragment);
|
||||
|
@ -49,15 +57,22 @@ public class MainActivity extends AppCompatActivity {
|
|||
switch (menuItem.getItemId()){
|
||||
case R.id.action_location:
|
||||
setSelectedFragment(LOCATION_LIST);
|
||||
sharedPreferences.edit()
|
||||
.putString(FRAGMENT_PREF_KEY, LOCATION_LIST)
|
||||
.commit();
|
||||
|
||||
break;
|
||||
case R.id.action_map:
|
||||
setSelectedFragment(MAP);
|
||||
sharedPreferences.edit()
|
||||
.putString(FRAGMENT_PREF_KEY, MAP)
|
||||
.commit();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
setSelectedFragment(LOCATION_LIST);
|
||||
setSelectedFragment(sharedPreferences.getString("last_fragment", LOCATION_LIST));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -59,4 +59,6 @@ RecyclerView -> Items der View wiederverwendbar machen
|
|||
- unterschiedliche Möglichkeiten der Speicherung
|
||||
- local storage (im App Verzeichnis)
|
||||
- external storage
|
||||
-
|
||||
- shared preferences (key - value pairs, internes XML file)
|
||||
- SQLite -> single file database
|
||||
- Permissions beim Speichern beachten
|
Loading…
Reference in New Issue