There are currently 6 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
806 5
今天我自己从头编写的activity类
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 12/31/14 23:31
/**
 *
 */
package com.example.users;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * @author Octopus
 *
 */
public class A extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a); //specify the XML layout file
        
        OnClickListener events = new OnClickListener() {
            @SuppressLint("SimpleDateFormat") @Override
            public void onClick(View v)
            {
                if (v.getId() == R.id.btnShowDate)
                {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    showdlg("The date", sdf.format(new Date()));
                }
                else if (v.getId() == R.id.btnShowTime)
                {
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                    showdlg("The time", sdf.format(new Date()));
                }
            }
        };
        Button btnShowDate = (Button)findViewById(R.id.btnShowDate);
        Button btnShowTime = (Button)findViewById(R.id.btnShowTime);
        btnShowDate.setOnClickListener(events);
        btnShowTime.setOnClickListener(events);
    }
    
    private void showdlg(String title, String msg)
    {
        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        ad.setIcon(android.R.drawable.ic_dialog_info);
        ad.setTitle(title);
        ad.setMessage(msg);
        ad.setPositiveButton("OK", null);
        ad.create().show();
    }
}

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 12/31/14 23:32
<?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" >
    
    <Button
        android:id="@+id/btnShowDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Button1" />

    <Button
        android:id="@+id/btnShowTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Button2" />

</LinearLayout>

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 12/31/14 23:32
可以运行。
android:layout_width="wrap_content"
        android:layout_height="wrap_content"
这两句不能少。。。
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 4 Posted at: 1/1/15 0:13
额,因为跨年敲钟,所以android程序的学习暂停了一会儿。现在恢复
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 5 Posted at: 1/1/15 0:13
我生成了我的第一个apk文件,一个是签名的,一个是未签名的。
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 6 Posted at: 1/1/15 0:15
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 806 Replies: 5
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 1/1/15 0:15
Bar Hot Posts
Bar Good Posts
Announcements