多肉啊~ 2022-11-08 19:17 采纳率: 57.1%
浏览 50
已结题

安卓如何缓存文本框内容

两个文本框,在第一次进入App时,输入内容;退出App,再次进入时,保留上次填写的内容。怎么写,我好像也调用不了输入事件的addTextChangedListener方法。还有就是密码文本框怎么做到显示和隐藏

img


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="@dimen/dp_100"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="用户名:"
                    android:textSize="@dimen/sp_18"
                    android:textColor="@color/color_242424"/>

                <EditText
                    android:id="@+id/Name_input"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/activity_item_bg"
                    android:paddingLeft="@dimen/dp_7"
                    android:gravity="center_vertical"
                    android:singleLine="true"
                    android:hint="请输入真实姓名"/>
            </LinearLayout>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginTop="@dimen/dp_7"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="@dimen/dp_100"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="密码:"
                    android:textSize="@dimen/sp_18"
                    android:textColor="@color/color_242424"/>

                <EditText
                    android:id="@+id/password_input"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/activity_item_bg"
                    android:inputType="textPassword"
                    android:paddingLeft="@dimen/dp_7"
                    android:gravity="center_vertical"
                    android:singleLine="true"
                    android:hint="请输入密码"/>
            </LinearLayout>

  • 写回答

6条回答 默认 最新

  • liranke 2022-11-08 20:34
    关注

    用SharedPreferences进行缓存;

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月11日
  • 创建了问题 11月8日

悬赏问题

  • ¥15 qml如何绘制三维笛卡尔坐标系并向其中添加折线?
  • ¥15 银河麒麟系统出现:/home/kylin/.config/caja错误
  • ¥20 在进行keil5环境中ti芯片可移植性验证出现了如图所示错误(参考的是立创和无名的视频)
  • ¥15 treelib库有读取树数据方法吗?
  • ¥15 咨询一个PYTHON的问题
  • ¥15 机器学习建模调参,roc评价指标
  • ¥15 RCS plot 包内置数据集使用时报错,如何解决?
  • ¥15 keil+mspm0g3507+二维总线舵机
  • ¥15 如何用wireshark分析找出url接口和param参数
  • ¥15 有谁知道这是阿里云那个应用的域名吗,怎么调用?