I'm trying to make a Character sheet for a DnD like game. The point is to take user input and store it for future viewing and changing. Maybe I'm looking for a solution that doesn't exists but I want the EditTexts to stay the way they are if the user closes the app or just goes back to the title screen. Following is part of the xml file for the user input, the java file is basically blank
**<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/scroll_s"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/name"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/name" android:inputType="textPersonName"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/player"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/player" android:inputType="textPersonName"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/pts_total" android:layout_weight="1"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/unspent_pts" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/pts_total" android:layout_weight="1" android:inputType="number"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/unspent_pts" android:layout_weight="1" android:inputType="number"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/ht" android:layout_weight="1"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/wt" android:layout_weight="1"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/age" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/height" android:inputType="number" android:layout_weight="1"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/weightt" android:inputType="number" android:layout_weight="1"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/age" android:inputType="number" android:layout_weight="1"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/size_mod"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/appearance"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/appearance" android:inputType="text"/> </LinearLayout> </ScrollView>**
Java file
package com.example.mapuchii.gurps; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class Character_activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_character_redo); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); // Read values from the "savedInstanceState"-object and put them in your textview } @Override protected void onSaveInstanceState(Bundle outState) { // Save the values you need from your textview into "outState"-object super.onSaveInstanceState(outState); } }
No comments:
Post a Comment