目前共有6篇帖子。 內容轉換:不轉換▼
 
點擊 回復
118 5
今天我自己从头编写的activity类
一派護法 十九級
1樓 發表于:2014-12-31 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();
    }
}

一派護法 十九級
2樓 發表于:2014-12-31 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>

一派護法 十九級
3樓 發表于:2014-12-31 23:32
可以运行。
android:layout_width="wrap_content"
        android:layout_height="wrap_content"
这两句不能少。。。
一派護法 十九級
4樓 發表于:2015-1-1 00:13
额,因为跨年敲钟,所以android程序的学习暂停了一会儿。现在恢复
一派護法 十九級
5樓 發表于:2015-1-1 00:13
我生成了我的第一个apk文件,一个是签名的,一个是未签名的。
一派護法 十九級
6樓 發表于:2015-1-1 00:15

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:118 回複數:5
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-1-1 00:15
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。