LAb 4 fertifg

This commit is contained in:
Philipp Wo 2019-03-15 18:43:55 +01:00
parent 2105cb8303
commit 8dd46f941c
2 changed files with 19 additions and 2 deletions

View File

@ -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));
}

View File

@ -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