views:

50

answers:

1

In my xml i have an edittext element like this

<EditText
android:id="@+id/hrvalue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="64"
android:textSize="18sp">
</EditText>

in my configuration class i want to read the value of the edittext and save it to a variable. In the edittext box the user will be inputting a number integer. I have wrote the following code

SharedPreferences prefs = self.getSharedPreferences("prefs", 0);
SharedPreferences.Editor edit = prefs.edit();
EditText hrvalue = (EditText)findViewById(R.id.hrvalue);
edit.putString("hrvalue"+appWidgetId,hrvalue.getText().toString());
edit.commit();

Could i read the value in the edittext box as integer?

Now I want to read the value as integer in my other class but i don't know how to do it. The sharedpreferences key,value pairs is a bit confusing for me. I wrote

int hrvalue=prefs.getInt("hrvalue"+appWidgetId,1);

Is this correct? Is that the correct way of reading from an edittext and adding it to sharedpreferences?Where is the value of an edittextbox stored? I had success with checkbox but not yet with edittext.

Thanks.

A: 

Use putInt instead of putString if you want to store an int. See this documention.

JRL