使用多个 TextView 保存 LinearLayout。 Android
Save LinearLayout with multiple TextView. Android
我有办法。每次按下按钮时,它们都会添加一个新数字(具有不同的颜色和引力)。点击几下后,我有了带有多个 TextView 的 LinearLayout。而且我不明白,如何保存它。关闭应用程序后,它会以空白布局打开。但我需要保存以前的 TextView。
public void someText(String message) {
TextView message = new TextView(MainActivity.this);
message.setText(message);
message.setBackgroundResource(R.drawable.textsmallest);
message.setTextColor(getResources().getColor(R.color.black));
message.setGravity(Gravity.START);
messageLayout.addView(message);
(非常抱歉,英语不是我的母语。)
您可以使用 SharedPreferences 将消息或其他值保存到 xml。
Link 这个:
Context ctx = MainActivity.this;
SharedPreferences sp = ctx.getSharedPreferences("SP", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("STRING_KEY", "string");
editor.putInt("INT_KEY", 0);
editor.putBoolean("BOOLEAN_KEY", true);
editor.commit();
我有办法。每次按下按钮时,它们都会添加一个新数字(具有不同的颜色和引力)。点击几下后,我有了带有多个 TextView 的 LinearLayout。而且我不明白,如何保存它。关闭应用程序后,它会以空白布局打开。但我需要保存以前的 TextView。
public void someText(String message) {
TextView message = new TextView(MainActivity.this);
message.setText(message);
message.setBackgroundResource(R.drawable.textsmallest);
message.setTextColor(getResources().getColor(R.color.black));
message.setGravity(Gravity.START);
messageLayout.addView(message);
(非常抱歉,英语不是我的母语。)
您可以使用 SharedPreferences 将消息或其他值保存到 xml。 Link 这个:
Context ctx = MainActivity.this;
SharedPreferences sp = ctx.getSharedPreferences("SP", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("STRING_KEY", "string");
editor.putInt("INT_KEY", 0);
editor.putBoolean("BOOLEAN_KEY", true);
editor.commit();