0

I have TextViews (DropDownList) and EditTexts in my activity.

<LinearLayout
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+DropDownList/tv_SubBrand"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+DropDownList/tv_InfoType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/txt_Remarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

I'd like to save the user input to my database but I'm having a problem in my Textviews because it is a DropDownList where in it has checkboxes inside the DropDownList and it can handle multiple options. Also, I can't cast it to OnCreate.

Is there any solution aside from using SharedPreferences? Can I resolve it when I use ArrayList? If yes, can you show me on how to do it?

androidBoomer
  • 3,357
  • 6
  • 32
  • 42

2 Answers2

1

Use SharedPreferences in onPause for current Activity as below and send the data to other activities as below:

@Override
protected void onPause() 
{
  super.onPause(); 
  SharedPreferences preferences = getSharedPreferences("sharedPrefs", 0);
  SharedPreferences.Editor editor = preferences.edit();  
  editor.putString("SearchText",edt.getText().toString());
      editor.putString("Text1",<Your TextView1>.getText().toString());
      editor.putString("Text2",<Your TextView2>.getText().toString());
  editor.commit();

}

and in other two Activities, get the data from Shared Preferences as below:

 SharedPreferences preferences = getSharedPreferences("sharedPrefs", 0);
 String edtText = preferences.getString("SearchText","");
 String strTextView1 = preferences.getString("Text1","");
 String strTextView2 = preferences.getString("Text2","");
Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
0

Using SharedPreferences. There'a nice thread here for it. With it, you can save the number in a Preference file (visible only for the current application and not in the file system). Like this one:

private final String PREFS_NAME  = "savefile";
private final String KEY_SUBBRAND    = "subb";
String strWithTheInput = ""
String strSavedValue = "";
SharedPreferences sharedPreferences = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);

//To put the phone in the file

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(KEY_SUBBRAND, strWithTheInput);
editor.commit();

//To retrieve the number

strSavedValue = sharedPreferences.getString("subb", null);
Community
  • 1
  • 1
g00dy
  • 6,752
  • 2
  • 30
  • 43