三个作业题

1.只生成了随机数排序没想出来

layout文件代码:

<?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: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"
    android:orientation="vertical"
    tools:context="com.example.my.myapplication.Test_Suijishu">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="生成随机数"
        android:onClick="bt1_onClick"
        android:id="@+id/bt_1"/>
</LinearLayout>

Activity代码:

package com.example.my.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Test_Suijishu extends AppCompatActivity {

    TextView tv_1;
    Button bt_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test__suijishu);
        tv_1=(TextView)findViewById(R.id.tv_1);
        bt_1=(Button)findViewById(R.id.bt_1);
    }
    public void bt1_onClick(View v)
    {
        int[]a=new int[6];
        String max="";
        String min="";
        String result="";
        for (int i=0;i<6;i++) {
            a[i] = (int) (Math.random() * 10);
            while (a[0] == 0) {
                a[0] = (int) (Math.random() * 10);
            }
            result += a[i];
        }
        tv_1.setText(result);
    }

}

截图:

 

2.

layout代码:

<?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: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"
    android:orientation="vertical"
    tools:context="com.example.my.myapplication.Test_duihuakuang">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="提示"
        android:onClick="tishi_onClick"/>
</LinearLayout>

Activity代码:

package com.example.my.myapplication;

import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class Test_duihuakuang extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_duihuakuang);

    }
    public void tishi_onClick(View v)
    {
        new AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("确定要删除吗?\n要删除,请点击“是”。")
                .setPositiveButton("否", null)
                .setNegativeButton("是", null)
                .show();
    }
}

截图:

3.

Layout代码:

<?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: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"
    android:orientation="vertical"
    tools:context="com.example.my.myapplication.Test_3">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="请输入电话号码"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:id="@+id/ed_phone"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="拨出此号码"
            android:id="@+id/bt_bd"
            android:onClick="bd_onClick"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="给此号码发短信"
            android:id="@+id/bt_fs"
            android:onClick="fs_onClick"/>
    </LinearLayout>
</LinearLayout>

Activity代码:

package com.example.my.myapplication;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Test_3 extends AppCompatActivity {

    EditText ed_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_3);
        ed_phone=(EditText)findViewById(R.id.ed_phone);
    }
    public void bd_onClick(View v)
    {
        String phone = getPhone();
        if (phone==null)return;
        Intent intent=new Intent(Intent.ACTION_DIAL);
        Uri uri=Uri.parse("tel:"+phone);
        intent.setData(uri);
        startActivity(intent);
    }
    public String getPhone()
    {
        String phone=ed_phone.getText().toString().trim();
        if (phone.length()==0)
        {
            Toast.makeText(Test_3.this, "请正确填写电话号码", Toast.LENGTH_SHORT).show();
            return null;
        }
        return phone;
    }
    public String getMessage()
    {
        String message=ed_phone.getText().toString().trim();
        if (message.length()==0)
        {
            Toast.makeText(Test_3.this, "请正确填写电话号码", Toast.LENGTH_SHORT).show();
            return null;
        }
        return message;
    }
    public void fs_onClick(View v)
    {
        String message = getMessage();
        if (message == null) return;
        Uri smsToUri = Uri.parse("smsto:message");
        Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);
        intent.setData(Uri.parse("smsto:"+message));
        startActivity(intent);
    }
}

截图:

posted on 2016-05-14 10:43  beens  阅读(129)  评论(0编辑  收藏  举报

导航