我在旋转设备时尝试保存EditText的值。 我正在使用Firebase数据库来保存并获取我的值。
$i = 1;
$tmp = ['fff'=>111,'aaa'=>100,'ddd'=>99,'ccc'=>87,'eee'=>45,'bbb'=>3,'ggg'=>1];
$prg = ['bbb','ccc'];
function doFilter($tmp,$prg,$i) {
$second = array_slice($tmp, $i, 1);
$snd = key($second);
if (!in_array(strtolower($snd),$prg)) {
$i++;
doFilter($tmp,$prg,$i);
} else {
// echo ccc
echo $snd;
return $snd;
}
}
$snd = doFilter($tmp,$prg,$i);
// echo NULL
echo $snd;
仅当值未存储在firebase中时才有效。
@Override
protected void onStart() {
super.onStart();
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Post post = dataSnapshot.getValue(Post.class);
if (mPostKey != null) {
titleEditText.setText(post.getTitle());
notesEditText.setText(post.getNotes());
} else {
titleEditText.setText(prefs.getString("titleText", post.getTitle()));
notesEditText.setText(prefs.getString("notesText", post.getTitle()));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mPostReference.addValueEventListener(postListener);
mPostListener = postListener;
}
我可以在清单中设置方向更改,但如果我这样做,当我向活动添加照片时,我仍然会松开文本。
我还尝试在super.onResume()之前和之后删除侦听器,如下所示:
@Override
protected void onResume() {
super.onResume();
prefs.edit().putString("titleText", titleEditText.getText().toString()).commit();
prefs.edit().putString("notesText", notesEditText.getText().toString()).commit();
}
任何帮助都是相关的。
答案 0 :(得分:0)
您是否尝试使用此覆盖功能
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation== Configuration.ORIENTATION_PORTRAIT)
{
}
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
}
}
答案 1 :(得分:0)
我已经开始工作了。如果有更好的答案,请与我分享。
if (hm.containsValue(1)) {
output.add(out);
} else {
output.add(out);
}
和onResume
output.add(out)
修改
如果我在文本前面编辑,此方法无法正确设置文本。
答案 2 :(得分:0)
为此目的更好地使用IsBroken
。例如:
savedInstaceState()
我认为这更好,因为它永远不会像// This function will invoked when rotation detected
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("titleText", titleEditText.getText().toString());
outState.putString("notesText", notesEditText.getText().toString());
super.onSaveInstanceState(outState);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this will restore it
if (savedInstanceState != null) {
titleEditText.setText(savedInstanceState.getString("titleText"));
notesEditText.setText(savedInstanceState.getString("notesText"));
}
}
那样保存