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

Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實(shí)例

 更新時(shí)間:2015年12月24日 15:12:46   作者:sgx425021234  
這篇文章主要介紹了Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實(shí)現(xiàn)方法,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了Android針對(duì)登錄數(shù)據(jù)的保存及回顯操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作。分享給大家供大家參考,具體如下:

LoginActivity.java:

package com.example.login; 
import java.util.Map; 
import android.app.Activity; 
import android.os.Bundle; 
import android.text.TextUtils; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.CheckBox; 
import android.widget.EditText; 
import android.widget.Toast; 
import com.example.login.service.FileService; 
public class LoginActivity extends Activity { 
  public EditText edit_name,edit_pass; 
  public Button btn_login; 
  public CheckBox box_remeber; 
  public FileService fileService; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 
    fileService=new FileService(this); 
    edit_name=(EditText) findViewById(R.id.edit_name); 
    edit_pass=(EditText) findViewById(R.id.edit_pass); 
    btn_login=(Button) findViewById(R.id.btn_login); 
    box_remeber=(CheckBox) findViewById(R.id.cbx_remember); 
    btn_login.setOnClickListener(new MyOnClickListener()); 
    Map<String, String> map=fileService.readFile("private.txt"); 
    if(map!=null){ 
      edit_name.setText(map.get("name")); 
      edit_pass.setText(map.get("pass")); 
    } 
  } 
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.login, menu); 
    return true; 
  } 
  class MyOnClickListener implements View.OnClickListener{ 
    @Override 
    public void onClick(View v) { 
      int id=v.getId(); 
      switch (id) { 
      case R.id.btn_login: 
        String name=edit_name.getText().toString(); 
        String pass=edit_pass.getText().toString(); 
        if(TextUtils.isEmpty(name)){ 
          Toast.makeText(LoginActivity.this, "用戶名不能為空", Toast.LENGTH_SHORT).show(); 
          return; 
        }else if(TextUtils.isEmpty(pass)){ 
          Toast.makeText(LoginActivity.this, "密碼不能為空", Toast.LENGTH_SHORT).show(); 
          return; 
        }else{ 
          if(box_remeber.isChecked()){ 
            LoginActivity.this.fileService.saveToRom(name, pass, "private.txt"); 
            Toast.makeText(LoginActivity.this, "用戶名和密碼已保存", Toast.LENGTH_SHORT).show(); 
          }else{ 
            Toast.makeText(LoginActivity.this, "用戶名和密碼不需要保存", Toast.LENGTH_SHORT).show(); 
          } 
        } 
        break; 
      default: 
        break; 
      } 
      /*if(id==btn_login.getId()){ 
        String name=edit_name.getText().toString(); 
        String pass=edit_pass.getText().toString(); 
        if(TextUtils.isEmpty(name)){ 
          Toast.makeText(LoginActivity.this, "用戶名不能為空", Toast.LENGTH_SHORT).show(); 
          return; 
        }else if(TextUtils.isEmpty(pass)){ 
          Toast.makeText(LoginActivity.this, "密碼不能為空", Toast.LENGTH_SHORT).show(); 
          return; 
        }else{ 
          if(box_remeber.isChecked()){ 
            LoginActivity.this.fileService.saveToRom(name, pass, "private.txt"); 
            Toast.makeText(LoginActivity.this, "用戶名和密碼已保存", Toast.LENGTH_SHORT).show(); 
          }else{ 
            Toast.makeText(LoginActivity.this, "用戶名和密碼不需要保存", Toast.LENGTH_SHORT).show(); 
          } 
        } 
      }*/ 
    } 
  } 
}

FileService.java:

package com.example.login.service; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.util.HashMap; 
import java.util.Map; 
import com.example.login.utils.StreamTools; 
import android.content.Context; 
public class FileService { 
  public Context context; 
  public FileService(Context context) { 
    this.context = context; 
  } 
  public boolean saveToRom(String name,String pass,String fileName){ 
    try{ 
      FileOutputStream fos=context.openFileOutput(fileName, Context.MODE_PRIVATE); 
      String result=name+":"+pass; 
      fos.write(result.getBytes()); 
      fos.flush(); 
      fos.close(); 
    }catch(Exception e){ 
      e.printStackTrace(); 
      return false; 
    } 
    return true; 
  } 
  public Map<String,String> readFile(String fileName){ 
    Map<String,String> map=null; 
    try{ 
      FileInputStream fis=context.openFileInput(fileName); 
      String value=StreamTools.getValue(fis); 
      String values[]=value.split(":"); 
      if(values.length>0){ 
        map=new HashMap<String, String>(); 
        map.put("name", values[0]); 
        map.put("pass", values[1]); 
      } 
    }catch(Exception e){ 
      e.printStackTrace(); 
    } 
    return map; 
  } 
}

StreamTools.java:

package com.example.login.utils; 
import java.io.ByteArrayOutputStream; 
import java.io.FileInputStream; 
public class StreamTools { 
  public static String getValue(FileInputStream fis) throws Exception{ 
    ByteArrayOutputStream stream=new ByteArrayOutputStream(); 
    byte[] buffer=new byte[1024]; 
    int length=-1; 
    while((length=fis.read(buffer))!=-1){ 
      stream.write(buffer,0,length); 
    } 
    stream.flush(); 
    stream.close(); 
    String value=stream.toString(); 
    return value; 
  } 
}

login_activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:paddingBottom="@dimen/activity_vertical_margin" 
  android:paddingLeft="@dimen/activity_horizontal_margin" 
  android:paddingRight="@dimen/activity_horizontal_margin" 
  android:paddingTop="@dimen/activity_vertical_margin" 
  tools:context=".LoginActivity" > 
  <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" > 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <TextView 
        android:id="@+id/view_name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/text_name" /> 
      <EditText 
        android:id="@+id/edit_name" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10"  
        android:inputType="textPersonName"> 
        <requestFocus /> 
      </EditText> 
    </LinearLayout> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <TextView 
        android:id="@+id/view_pass" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/text_pass" /> 
      <EditText 
        android:id="@+id/edit_pass" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:inputType="textPassword" /> 
    </LinearLayout> 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <Button 
        android:id="@+id/btn_login" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.17" 
        android:text="@string/text_login" /> 
      <CheckBox 
        android:id="@+id/cbx_remember" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="80dp" 
        android:text="@string/text_rember" /> 
    </LinearLayout> 
  </LinearLayout> 
</RelativeLayout>

String.xml:

<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<stringname="app_name">login</string>
<stringname="action_settings">Settings</string>
<stringname="hello_world">Login</string>
<stringname="text_name">用戶名:</string>
<stringname="text_pass">密 碼:</string>
<stringname="text_login">登陸</string>
<stringname="text_rember">記住密碼</string>
</resources>

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android Studio中使用jni進(jìn)行opencv開發(fā)的環(huán)境配置方法

    Android Studio中使用jni進(jìn)行opencv開發(fā)的環(huán)境配置方法

    今天小編就為大家分享一篇Android Studio中使用jni進(jìn)行opencv開發(fā)的環(huán)境配置方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解

    Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • kotlin延遲初始化和密封類詳細(xì)講解

    kotlin延遲初始化和密封類詳細(xì)講解

    Kotlin語(yǔ)言的許多特性,包括變量不可變,變量不可為空,等等。這些特性都是為了盡可能地保證程序安全而設(shè)計(jì)的,但是有些時(shí)候這些特性也會(huì)在編碼時(shí)給我們帶來(lái)不少的麻煩,下面我們來(lái)了解延遲初始化和密封類的特點(diǎn)
    2022-11-11
  • Android底部導(dǎo)航組件BottomNavigationView

    Android底部導(dǎo)航組件BottomNavigationView

    這篇文章主要介紹了Android底部導(dǎo)航組件BottomNavigationView,BottomNavigationView是相當(dāng)于一個(gè)導(dǎo)航的標(biāo)簽,但是它的形式就是像QQ微信之類的界面,至于寫出后怎樣綁定這三個(gè)界面,就得用Fragment,寫這三個(gè)頁(yè)面的布局
    2023-03-03
  • Android開發(fā)入門之Notification用法分析

    Android開發(fā)入門之Notification用法分析

    這篇文章主要介紹了Android中Notification用法,較為詳細(xì)的分析了Notification的功能、使用步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-07-07
  • Android判斷現(xiàn)在所處界面是否為home主桌面的方法

    Android判斷現(xiàn)在所處界面是否為home主桌面的方法

    這篇文章主要介紹了Android判斷現(xiàn)在所處界面是否為home主桌面的方法,涉及Android界面判斷的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Flutter封裝組動(dòng)畫混合動(dòng)畫AnimatedGroup示例詳解

    Flutter封裝組動(dòng)畫混合動(dòng)畫AnimatedGroup示例詳解

    這篇文章主要為大家介紹了Flutter封裝組動(dòng)畫混合動(dòng)畫AnimatedGroup示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Android實(shí)現(xiàn)圖片裁剪處理的操作步驟

    Android實(shí)現(xiàn)圖片裁剪處理的操作步驟

    這篇文章介紹了構(gòu)建具有圖片選擇、裁剪(含手動(dòng)縮放和旋轉(zhuǎn))及保存到自定義路徑功能的 Android 應(yīng)用 demo 的步驟,包括設(shè)置權(quán)限、創(chuàng)建布局文件、實(shí)現(xiàn)自定義視圖CustomCropImageView、更新Activity邏輯等,最終完成了具有完整裁剪功能的應(yīng)用,需要的朋友可以參考下
    2025-01-01
  • Android MotionEvent中g(shù)etX()和getRawX()的區(qū)別實(shí)例詳解

    Android MotionEvent中g(shù)etX()和getRawX()的區(qū)別實(shí)例詳解

    這篇文章主要介紹了Android MotionEvent中g(shù)etX()和getRawX()的區(qū)別實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Flutter異步操作實(shí)現(xiàn)流程詳解

    Flutter異步操作實(shí)現(xiàn)流程詳解

    在Flutter中,借助 FutureBuilder 組件和 StreamBuilder 組件,可以非常方便地完成異步操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2022-09-09

最新評(píng)論

昌乐县| 绥德县| 台山市| 壶关县| 大邑县| 宜川县| 甘洛县| 襄垣县| 平远县| 镇平县| 建宁县| 丰都县| 台南市| 天长市| 中超| 攀枝花市| 漳州市| 海南省| 江永县| 连南| 郸城县| 贺州市| 东阿县| 北海市| 信宜市| 山丹县| 敦化市| 临桂县| 大丰市| 唐山市| 互助| 清苑县| 渑池县| 耒阳市| 淮北市| 丹阳市| 华安县| 马关县| 汾阳市| 韶山市| 永登县|