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));
                                }
                            }
                    );
        }
    }
    
  • 相关阅读:
    Codeforces 1105D Kilani and the Game【BFS】
    Codeforces 1096D Easy Problem 【DP】
    Codeforces 920F
    Codeforces 1076D Edge Deletion 【最短路+贪心】
    POJ 3090 Visible Lattice Points 【欧拉函数】
    POJ 1284 Primitive Roots (欧拉函数+原根)
    HDU 2841-Visible Trees 【容斥】
    HDU 1796 How many integers can you find 【容斥】
    HDU 4135 Co-prime (容斥+分解质因子)
    CodeForces 161D Distance in Tree【树形DP】
  • 原文地址:https://www.cnblogs.com/YUESEtaimei/p/6832246.html
Copyright © 2011-2022 走看看