目前共有6篇帖子。 内容转换:不转换▼
 
点击 回复
120 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)
 

本帖信息

点击数:120 回复数:5
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2015-1-1 00:15
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。