最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中SharedPreferences簡單使用實例

 更新時間:2021年10月26日 10:25:14   作者:JustingWang_1  
這篇文章主要介紹了Android中SharedPreferences簡單使用案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了SharedPreferences簡單使用案例,供大家參考,具體內(nèi)容如下

MainActivity:

public class SharedPreferencesTestActivity extends Activity implements View.OnClickListener{
  private EditText editText;
  private TextView textView;
  private Button write;
  private Button read;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shared_preferences_test);
    initView();

    write.setOnClickListener(this);
    read.setOnClickListener(this);
  }

  private void initView() {
    editText=(EditText)findViewById(R.id.Edit_Test);
    textView=(TextView)findViewById(R.id.Text_Test);
    write=(Button)findViewById(R.id.write);
    read=(Button)findViewById(R.id.read);
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()){
      case R.id.write:
        String some=editText.getText().toString();
        SharedPreferences pref = SharedPreferencesTestActivity.this.getSharedPreferences("data",MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putString("Content",some);
        editor.commit();
        Toast.makeText(SharedPreferencesTestActivity.this, "寫入成功" , Toast.LENGTH_LONG).show();
        editText.setText("");
        break;
      case R.id.read:
        SharedPreferences pre = getSharedPreferences("data",MODE_PRIVATE);
        String name = pre.getString("Content","");
        textView.setText(name);
        Toast.makeText(SharedPreferencesTestActivity.this, "讀取成功" , Toast.LENGTH_LONG).show();
        break;

    }
  }
}

MainActivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  tools:context="com.fae.mobile.testActivity.SharedPreferencesTestActivity">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText

      android:textColor="@color/red"
      android:background="@null"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/Edit_Test"
      android:layout_weight="1"
      />
    <TextView
      android:textColor="@color/blue"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/Text_Test"
      android:layout_weight="1"/>
  </LinearLayout>
  <Button
    android:layout_marginTop="25dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/read"
    android:text="讀"/>
  <Button
    android:layout_marginTop="25dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/write"
    android:text="寫"/>

</LinearLayout>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中常見的圖形繪制方式總結(jié)

    Android中常見的圖形繪制方式總結(jié)

    Android中繪制圖片或形狀是我們常遇到的事情,通過最近的學(xué)習(xí)與在網(wǎng)上學(xué)習(xí)的案例與資料那么我今天就總結(jié)一下,這篇文章主要給大家介紹了關(guān)于Android中常見的圖形繪制方式,需要的朋友可以參考下
    2021-07-07
  • Android通過記住密碼功能學(xué)習(xí)數(shù)據(jù)存儲類SharedPreferences詳解及實例

    Android通過記住密碼功能學(xué)習(xí)數(shù)據(jù)存儲類SharedPreferences詳解及實例

    這篇文章主要通過“記住密碼”實例功能學(xué)習(xí)為大家介紹了Android數(shù)據(jù)存儲類SharedPreferences,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android中RecyclerView的item寬高問題詳解

    Android中RecyclerView的item寬高問題詳解

    RecyclerView出現(xiàn)已經(jīng)有一段時間了,相信大家肯定不陌生了,下面這篇文章主要給大家介紹了關(guān)于Android中RecyclerView的item寬高問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • Android編程中的四大基本組件與生命周期詳解

    Android編程中的四大基本組件與生命周期詳解

    這篇文章主要介紹了Android編程中的四大基本組件與生命周期,結(jié)合實例形式較為詳細(xì)的分析了Android四大組件及生命周期的相關(guān)概念與使用技巧,需要的朋友可以參考下
    2015-12-12
  • Android5.0 旋轉(zhuǎn)菜單實例詳解

    Android5.0 旋轉(zhuǎn)菜單實例詳解

    這篇文章主要介紹了 Android5.0 旋轉(zhuǎn)菜單的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2016-12-12
  • Android拍照上傳功能示例代碼

    Android拍照上傳功能示例代碼

    這篇文章主要介紹了Android拍照上傳功能用法,結(jié)合實例形式詳細(xì)分析了Android拍照上傳功能所涉及的相關(guān)知識點(diǎn)與功能實現(xiàn)技巧,需要的朋友可以參考下
    2016-08-08
  • Android內(nèi)存溢出及內(nèi)存泄漏原因進(jìn)解析

    Android內(nèi)存溢出及內(nèi)存泄漏原因進(jìn)解析

    這篇文章主要介紹了Android內(nèi)存溢出及內(nèi)存泄漏原因解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-08-08
  • android activity設(shè)置無標(biāo)題實現(xiàn)全屏

    android activity設(shè)置無標(biāo)題實現(xiàn)全屏

    本文將詳細(xì)介紹Android如何設(shè)置Activity全屏和無標(biāo)題的實現(xiàn)方法,需要的朋友可以參考下
    2012-12-12
  • Android通過Movie展示Gif格式圖片

    Android通過Movie展示Gif格式圖片

    這篇文章主要介紹了Android通過Movie展示Gif格式圖片的相關(guān)資料,需要的朋友可以參考下
    2016-04-04
  • Android網(wǎng)絡(luò)請求框架Retrofit詳解

    Android網(wǎng)絡(luò)請求框架Retrofit詳解

    這篇文章主要為大家詳細(xì)介紹了Android網(wǎng)絡(luò)請求框架Retrofit,使用Retrofit2.0.0版本進(jìn)行實例演示,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08

最新評論

株洲市| 石屏县| 土默特左旗| 石柱| 隆回县| 万荣县| 常德市| 红安县| 鲁甸县| 保康县| 两当县| 安西县| 东乌| 武安市| 仁布县| 慈利县| 分宜县| 巴林左旗| 新闻| 扎赉特旗| 锦屏县| 逊克县| 天峨县| 仙游县| 托里县| 南溪县| 鄂尔多斯市| 思茅市| 正镶白旗| 平南县| 东至县| 文山县| 梨树县| 新龙县| 历史| 乐平市| 富平县| 社旗县| 乐亭县| 友谊县| 利辛县|