黑马程序员技术交流社区

标题: 仿QQ登录实现 [打印本页]

作者: linxy06    时间: 2015-11-24 20:15
标题: 仿QQ登录实现
public class MainActivity extends Activity {
        private static final String Tag = "MainActivity";
        private EditText et_qq;
        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);
                et_pwd = (EditText) findViewById(R.id.et_pwd);
                cb_remember = (CheckBox) findViewById(R.id.cb_remember);
                Log.i(Tag,"oncreate 被调用");
                //完成数据的回显。
                readSavedData();
        }
        //读取保存的数据
        private void readSavedData() {
                // getFilesDir() == /data/data/包名/files/  获取文件的路径 一般系统是不会清理的。 用户手工清理,系统会有提示。
                // getCacheDir()==  /data/data/包名/cache/ 缓存文件的路径 当系统内存严重不足的时候 系统会自动的清除缓存 用户手工清理系统没有提示
                File file = new File(getFilesDir(),"info.txt");
                if(file.exists()&&file.length()>0){
                        try {
                                //FileInputStream fis = new FileInputStream(file);
                                FileInputStream fis =this.openFileInput("info.txt");
                                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                                //214342###abcdef
                                String info = br.readLine();
                                String qq = info.split("###")[0];
                                String pwd = info.split("###")[1];
                                et_qq.setText(qq);
                                et_pwd.setText(pwd);
                                fis.close();
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                }
        }
        /**
         * 登陆按钮的点击事件,在点击事件里面获取数据
         * @param view
         */
        public void login(View view){
                String qq = et_qq.getText().toString().trim();
                String pwd = et_pwd.getText().toString().trim();
                if(TextUtils.isEmpty(qq)||TextUtils.isEmpty(pwd)){
                        Toast.makeText(this, "qq号码或者密码不能为空", 0).show();
                        return;
                }
                //判断用户是否勾选记住密码。
                if(cb_remember.isChecked()){
                        //保存密码
                        Log.i(Tag,"保存密码");
                        try {
//                                File file = new File(getFilesDir(),"info.txt");
//                                FileOutputStream fos = new FileOutputStream(file);
                                FileOutputStream fos = this.openFileOutput("info.txt", 0);
                                //214342###abcdef
                                fos.write((qq+"###"+pwd).getBytes());
                                fos.close();
                                Toast.makeText(this, "保存成功", 0).show();
                        } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(this, "保存失败", 0).show();
                        }
                }else{
                        //无需保存密码
                        Log.i(Tag,"无需保存密码");
                }
        }
}



作者: 呐小伟    时间: 2015-11-24 21:26
第一种:局部结构体
#include<stdio.h>
int main(){
    //一种正常的局部结构体
  
struct person{
    char *name;
    int age;
};
//赋值与取值
    struct person per={"angelaBaby",23};
    printf("name=%s---age=%d\n",per.name,per.age);
    return 0;
}
第二种:全局结构体
#include<stdio.h>
struct person{    //一种全局结构体
    char *name;
    int age;
}per={"angelaBaby",23};
int main(){
//赋值与取值
    printf("name=%s---age=%d\n",per.name,per.age);
    return 0;
}
第三种:匿名类型结构体
//匿名类型结构体
#include<stdio.h>
int main(){
    struct {
        char *name;
        int age;
    }per={"angelaBaby",23};
   
    printf("name=%s---age=%d\n",per.name,per.age)
   
}
第四种:嵌套类型结构体
//嵌套类型结构体
#include<stdio.h>
int main(){
    struct person{
        char *name;
        int age;
    }p1;
    struct actor{
        char *name;
        int age;
        struct person p1;
    }a1={"huangXiaoMing",30,
        {"angelaBaby",23}};
    printf("演员名字是= %s,年龄是 %d,人名字是= %s,年龄是 %d\n",a1.name,a1.age,a1.p1.name,a1.p1.age);//需注意的地方!!!
    return 0;
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2