Android Design QQ interface and how to save data to SD card and memory

Source: Internet
Author: User
Tags gettext

1. First set up the QQ display interface

Interface Two EditText two TextView, a selection box and a button

2. Design steps

① Main Page Surface design

1 <TextView2         Android:layout_width= "Fill_parent"3 Android:layout_height= "Wrap_content"4 Android:text= "Please enter the QQ number!" "5 />6 <EditText7         Android:layout_width= "0DP"8 Android:layout_height= "Wrap_content"9 />Ten <TextView One         Android:layout_width= "Fill_parent" A Android:layout_height= "Wrap_content" - Android:text= "Please enter the QQ password!" " - /> the  <EditText -         Android:layout_width= "0DP" - Android:layout_height= "Wrap_content" - /> + <CheckBox -         Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" A Android:text= "Save Password" at /> -  <Button -         Android:layout_width= "0DP" - Android:layout_height= "Wrap_content" - Android:text= "Login" - />

② Getting Information

Add address information for each control

1  <EditText2         Android:id= "@+id/et_qq"//Add address information to it3 />4  <EditText5         Android:id= "@+id/et_pwd"6 />7  <CheckBox8         Android:id= "@+id/cb_remember"9 />Ten <Button One         Android:onclick= "Login" A />

Control to add properties to it, and to obtain its value.

When the user does not enter the account and password, or only enter the account and password, then the reminder "account and password cannot be empty"

To add an event to the button

public class Mainactivity extends appcompatactivity {    private static final String tag= "tag";    Private EditText et_qq;//Create variable    private EditText et_pwd;    Private CheckBox Cb_remember;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        ET_QQ = (EditText) Findviewbyid (R.ID.ET_QQ);//initialization variable fixed notation        et_pwd = (EditText) Findviewbyid (r.id.et_pwd);        Cb_remember = (CheckBox) Findviewbyid (r.id.cb_remember);}    public void Login (view view) {        String qq= et_qq.gettext (). toString ();        String pwd = Et_pwd.gettext (). toString ();        if (Textutils.isempty (QQ) | | Textutils.isempty (pwd) {            toast.maketext (this, "User name password cannot be empty", Toast.length_short). Show ();//toast when the user name is empty, "User name password cannot be empty"        }else{            //Login action}}

Display effect:

③ See if "Remember Password" is selected in the process

Print log:

# #日志的级别
LOG.V ("mainactivity", "I am a Log");//v:verbose alert Black
LOG.D ("mainactivity", "I am a Log");//d:debug Debug Blue
LOG.I ("mainactivity", "I am a Log");//i:info Reminder Green
LOG.W ("mainactivity", "I am a Log");//w:warn warning Orange
LOG.E ("mainactivity", "I am a Log");//e:error error Red

View Effects

The effect of saving passwords is not clicked:

Click the effect to save the password:

④ storing information in a file

This program runs on the phone, which is always stored in the root directory on the phone, but the root directory is forbidden to write, so the error. Then save the information to the SD card

Easily violated by spam software.

To add a permission setting in Androidmanifest.xml

Results:

Open Android Studio tools->android->android Device Monitor Error:

The error content is:

Workaround:

In Task Manager, turn off all the monitor.exe processes that are open and reopen them.

Read user-saved password information

1 try{2 File File = new file ("/mnt/sdcard/info.txt");//path of the external SD card3 FileInputStream fis = new FileInputStream (file);4 bufferedreader br = new BufferedReader (new InputStreamReader (FIS));5 String info = br.readline ();6 String Qq=info.split ("# # #") [0];7 String Pwd=info.split ("# # #") [1];8 Et_qq.settext (QQ);9 Et_pwd.settext (PWD);Ten } catch (Exception e) { One e.printstacktrace (); A         }} -Read the file where the user saved the password

The effect is as follows:

After you click Save Password, the previous account and password are still there.

Android under Data storage:

*SD Card

1. Declaring the rights to write the SD card (manifest file)

2.environment.getexternalstoragedirectory ()//Get the directory under the current SD card file

3. Determine the status of the SD card and whether it can be read

Environment.getexternalstoragestate ();

4.SD card available, but the SD card is full, (judging the remaining space of the SD card)

1 environment.getexternalstoragedirectory (). Getusablespace ();//Determine the available space or
2.environment.getexternalstoragedirectory (). Getfreespace ();

I rookie, just his own experience of the experiment, data storage did not understand, and so I understand, and then fill a

Android Design QQ interface and how to save data to SD card and memory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.