测试姓名性别LOL人品运气Android代码实现闲来无事练练手^_^


代码实现 UI布局  按顺序
第一页
<pre name="code" class="html"><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=".MainActivity" 
    android:background="@drawable/ll">

    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="LOL女神为您测人品,超神,五杀杠杠滴"
        android:textColor="#E0E0E0"
        android:textSize="30sp" 
        android:layout_centerHorizontal="true"
       android:layout_alignParentBottom="true"
        />
    
   

</RelativeLayout>
第二页
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="游戏主播MISS为您测人品"
        android:textColor="#8B008B"
        android:textSize="25sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:orientation="vertical" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:paddingLeft="50dp"
                android:text="请确认性别"
                android:textSize="20dp" />

            <RadioGroup
                android:id="@+id/sex"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:orientation="horizontal" >

                <RadioButton
                    android:id="@+id/nan"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="男" />

                <RadioButton
                    android:id="@+id/nv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="女" />

                <RadioButton
                    android:id="@+id/zhongxing"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="中性" />
            </RadioGroup>

            <EditText
                android:id="@+id/et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:hint="请输入您的姓名" >

                <requestFocus />
            </EditText>
        </LinearLayout>

        <ImageView
            android:id="@+id/iv"
            android:layout_width="0dp"
            android:layout_height="150dp"
            android:layout_weight="1"
            android:src="@drawable/miss" 
            android:onClick="tupian"/>
    </LinearLayout>

</LinearLayout>
第三页
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:gravity="center"
    android:background="#55ff0000">
    <TextView 
        android:id="@+id/jieguo"
         android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="计算结果"
    android:textSize="25sp"
    android:textStyle="bold"
    android:textColor="#FFFFFF"/>
    

</LinearLayout>
清单文件配置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/miss1"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:theme="@android:style/Theme.Light.NoTitleBar"
            android:name="com.example.activity.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity
             android:theme="@android:style/Theme.Light.NoTitleBar"
            android:name="com.example.activity.MyActivity"
            android:label="@string/app_name" >
        </activity>
        
        <activity
             android:theme="@android:style/Theme.Light.NoTitleBar"
            android:name="com.example.activity.YouActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>
代码实现

 
第一页
package com.example.activity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class MainActivity extends Activity {


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>protected void onCreate(Bundle savedInstanceState) {
<span style="white-space:pre">		</span>super.onCreate(savedInstanceState);
<span style="white-space:pre">		</span>setContentView(R.layout.activity_main);
<span style="white-space:pre">		</span>new Thread(){
<span style="white-space:pre">			</span>public void run() {
<span style="white-space:pre">				</span>try {
<span style="white-space:pre">					</span>Thread.sleep(2000);
<span style="white-space:pre">					</span>
<span style="white-space:pre">				</span>} catch (InterruptedException e) {
<span style="white-space:pre">					</span>// TODO Auto-generated catch block
<span style="white-space:pre">					</span>e.printStackTrace();
<span style="white-space:pre">				</span>}
<span style="white-space:pre">				</span>Intent intent=new Intent();
<span style="white-space:pre">				</span>intent.setClass(MainActivity.this, MyActivity.class);
<span style="white-space:pre">				</span>startActivity(intent);
<span style="white-space:pre">				</span>finish();
<span style="white-space:pre">				</span>
<span style="white-space:pre">			</span>};
<span style="white-space:pre">		</span>}.start();
<span style="white-space:pre">	</span>}




}
第二页
<pre name="code" class="html">package com.example.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MyActivity extends Activity {
	private RadioGroup sex;
	private EditText et;
	private	ImageView iv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.myactivity);
		sex=(RadioGroup) findViewById(R.id.sex);
		 et=(EditText) findViewById(R.id.et);
		 iv=(ImageView) findViewById(R.id.iv);
	}
	public void tupian(View v){
		String name=et.getText().toString().trim();
		if(TextUtils.isEmpty(name)){
			Toast.makeText(MyActivity.this, "请输入姓名", 0).show();
			return;}
		int sex1=sex.getCheckedRadioButtonId();
		Intent intent=new Intent();
		intent.setClass(MyActivity.this, YouActivity.class);
		intent.putExtra("name", name);
		intent.putExtra("sex1", sex1);
		startActivity(intent);
			
		
	}

}
第三页
package com.example.activity;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
import android.widget.Toast;

public class YouActivity extends Activity {
	TextView jieguo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.youactivity);
		jieguo = (TextView) findViewById(R.id.jieguo);
		Intent intent = getIntent();
		String name = intent.getStringExtra("name");
		int sex = intent.getIntExtra("sex1", R.id.nan);
		String ss=jisuan(name, sex);
		/*File file=new File(Environment.getExternalStorageDirectory(), "jieguo.txt");
		try {
			
		if(!file.exists()){
			BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
			bw.write(ss);
			bw.close();
		
		}else{
			BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
			byte[] bye=new byte[1024];
			String s=null;
			StringBuffer sb=new StringBuffer();
			while((s=br.readLine())!=null){
				sb.append(s);
			}
			BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
			bw.write(sb.append(ss).toString());
			br.close();
			bw.close();
		}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		
		}*/
		}
	

	private String jisuan(String name, int sex) {
		String sexed = null;
		byte[] b = null;
		try {
			switch (sex) {

			case R.id.nan:
				b = name.getBytes();
				sexed = "男";
				break;
			case R.id.nv:

				b = name.getBytes("GBK");
				sexed = "女";
				break;
			case R.id.zhongxing:
				b = name.getBytes("iso-8859-1");
				sexed = "中性";
				break;

			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		;
		int result = 0;
		for (byte by : b) {
			result += Math.abs(by & 0xff);

		}
//		Toast.makeText(YouActivity.this, "" + result, 0).show();
		int a = result % 100;
		String ss = null;
		if (a >= 90) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed + "\n"+"人品:"+a+ "\n" + "评价:" 
					+ "您将成为最强王者";
		} else if (a >= 80) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed + "\n" +"人品:"+a+ "\n" + "评价:" 
					+ "五杀超神秀操作";
		} else if (a >= 70) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed + "\n" +"人品:"+a+ "\n" + "评价:" 
					+ "不错哦,继续努力";
		} else if (a >= 60) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed + "\n" +"人品:"+a+ "\n" + "评价:" 
					+ "还行,加油";
		} else if (a >= 50) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed + "\n"+"人品:"+a + "\n" + "评价:" 
					+ "技术太水了";
		} else if (a >= 40) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed  + "\n"+"人品:"+a+ "\n" + "评价:" 
					+ "新手吧";
		} else if (a >= 30) {
			ss = "姓名:" + name + "\n" + "性别:" + sexed  + "\n"+"人品:"+a+ "\n" + "评价:"
					+ "不想说什么了";
		} else {
			ss = "姓名:" + name + "\n" + "性别:" + sexed  + "\n"+"人品:"+a+ "\n" + "评价:"
					+ "欢迎来到LOL,菜鸟就是你了";
		}
		jieguo.setText(ss);
		return ss;
	}

}



 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值