zoukankan      html  css  js  c++  java
  • 张学友

    界面布局

    *利用LinearLayout线性布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_wuyue9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/name" />
        <EditText
            android:id="@+id/age"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/age"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center">
    
            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/in"
                android:textSize="20sp"
                android:layout_marginRight="40dp"/>
    
            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/read"
                android:textSize="20sp"/>
        </LinearLayout>
    </LinearLayout
    

    java的代码的实现

    package cn.edu.niit.aaaaaaaaaaaaaaaaaaaa;
    
            import android.app.Activity;
            import android.content.Context;
            import android.content.SharedPreferences;
            import android.content.SharedPreferences.Editor;
            import android.os.Bundle;
            import android.view.View;
            import android.widget.Button;
            import android.widget.EditText;
            import android.widget.Toast;
    
    class SharedPreferencesActivity extends Activity
    {
        private  EditText name=null;
        private EditText age=null;
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_wuyue9);
            name=(EditText)findViewById(R.id.name);
            age=(EditText)findViewById(R.id.age);
            Button saveButton=(Button)findViewById(R.id.button1);
            Button restorationButton=(Button)findViewById(R.id.button2);
            //写入信息
            saveButton.setOnClickListener
                    (
                            new View.OnClickListener()
                            {
                                @Override
                                public void onClick(View v)
                                {
    
                                    String web_name=name.getText().toString();
                                    String true_age=age.getText().toString();
                                    SharedPreferences preferences=getSharedPreferences("softinfo",Context.MODE_WORLD_READABLE);
                                    Editor edit=preferences.edit();
                                    edit.putString("name", web_name);
                                    edit.putInt("age",new Integer(true_age));
                                    edit.commit();
                                    Toast.makeText(SharedPreferencesActivity.this, R.string.success,Toast.LENGTH_LONG).show();
    
                                }
                            }
                    );
            //读取信息
            restorationButton.setOnClickListener
                    (
                            new View.OnClickListener()
                            {
    
                                @Override
                                public void onClick(View v)
                                {
             SharedPreferences ferences=getSharedPreferences("softinfo",0);
             String true_name=ferences.getString("name", "");
            int true_age=ferences.getInt("age", 20);
            name.setText(true_name);
        age.setText(String.valueOf(true_age));
                                }
                            }
                    );
        }
    }
    
  • 相关阅读:
    局域网内其他机器访问本机80网站失败记录
    百度经纬度获取
    Win10安装安卓ADB驱动
    SQL Server 查看数据库是否存在阻塞
    IP地址接口小结
    雄冠条码PV系统-2016-05-17-收获
    slf4j MDC使用
    Java NIO之通道
    Java NIO之缓冲区
    记一次ThreadPoolExecutor面试
  • 原文地址:https://www.cnblogs.com/YUESEtaimei/p/6832246.html
Copyright © 2011-2022 走看看