我从许多文本字段中获取值,并将其值存储在我的首选项文件中的相应首选项值中。我不知道我做错了。这是我的代码:
public void onClick(View source) {
switch(source.getId())
{
case R.id.imageButtonNext:
String longitude=String.valueOf(editTextLongitude.getText());
String latitude=String.valueOf(editTextLatitude.getText());
String currentTime=String.valueOf(textViewCurrentTime.getText());
String agentNo=String.valueOf(editTextAgentno.getText());
String description=String.valueOf(editTextDescription.getText());
String mobile_number=String.valueOf(editTextMobileNo.getText());
moredetails=getSharedPreferences("prefs",0);
SharedPreferences.Editor editor=moredetails.edit();
editor.putString("latitude",latitude);
editor.putString("longitude",longitude);
editor.putString("currentTime",currentTime);
editor.putString("agentNo",agentNo);
editor.putString("description",description);
editor.putString("mobileNo",mobile_number);
String lat=moredetails.getString("latitude","");
Toast.makeText(CurrentLocation.this,lat,Toast.LENGTH_LONG).show();
break;
}
}
首选文件:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:key="latitude" android:title="@string/latitudeString"></Preference>
<Preference android:key="@string/longitudeString" android:title="@string/longitudeString"></Preference>
<Preference android:key="@string/agentNoString" android:title="@string/agentNoString"></Preference>
<Preference android:key="@string/assistantNameString" android:title="@string/assistantNameString"></Preference>
<Preference android:key="@string/mobilenoString" android:title="@string/mobilenoString"></Preference>
<Preference android:key="@string/cashFloatString" android:title="@string/cashFloatString"></Preference>
<Preference android:key="@string/efloatString" android:title="@string/efloatString"></Preference>
<Preference android:key="@string/posterAString" android:title="@string/posterAString"></Preference>
<Preference android:key="@string/posterBString" android:title="@string/posterBString"></Preference>
<Preference android:key="@string/smexnoString" android:title="@string/smexnoString"></Preference>
<Preference android:key="@string/trainingString" android:title="@string/trainingString"></Preference>
<Preference android:key="currentTime" android:title="currentTime"></Preference>
</PreferenceScreen>
我真的很感激帮助。
答案 0 :(得分:3)