程序开始运行时强制关闭,Adapter方法出错(用来实现闹钟的时间列表) -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

程序开始运行时强制关闭,Adapter方法出错(用来实现闹钟的时间列表)

2016-06-16 09:37:53 1907 0
package pcAlarm.pack;

import java.util.Calendar;
 import java.util.Currency;

import pcAlarm.pack.PCAlarmActivity;

import android.app.Activity;
 import android.app.TimePickerDialog;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.provider.Contacts;
 import android.view.View;
 import android.widget.ArrayAdapter;
 import pcAlarm.pack.AlarmView;
 import pcAlarm.pack.AlarmView.AlarmData;
 import android.view.View.OnClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.ListView;
 import android.widget.TabHost;
 import android.widget.TimePicker;

public class PCAlarmActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 tabHost = (TabHost)findViewById(android.R.id.tabhost);
 tabHost.setup();
    tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟").setContent(R.id.tabAlarm));


    btnAddAlarm=(Button)findViewById(R.id.btnAddAlarm);
    lvListView=(ListView)findViewById(R.id.lvListView);

    adapter=new ArrayAdapter<PCAlarmActivity.AlarmData>(getContext(), android.R.layout.simple_list_item_1);
    lvListView.setAdapter(adapter);

    adapter.add(new AlarmData(System.currentTimeMillis()));





    btnAddAlarm.setOnClickListener(new OnClickListener() {

        private Calendar mcalender;

        @Override
        public void onClick(View v) {
            Calendar.getInstance().setTimeInMillis(System.currentTimeMillis());
            mcalender = Calendar.getInstance();
            int mHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
            int mMinute = Calendar.getInstance().get(Calendar.MINUTE);
            new TimePickerDialog(PCAlarmActivity.this, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    // TODO Auto-generated method stub
                    Calendar.getInstance().setTimeInMillis(System.currentTimeMillis());
                    Calendar.getInstance().set(Calendar.HOUR_OF_DAY, hourOfDay);
                    Calendar.getInstance().set(Calendar.MINUTE, minute);
                    Calendar.getInstance().set(Calendar.SECOND, 0);
                    Calendar.getInstance().set(Calendar.MILLISECOND, 0);

                    AlarmData add = new AlarmData(Calendar.getInstance().getTimeInMillis());




                }
            }, mHour, mMinute, true).show();
        }
    });

}
private Context getContext() {
    // TODO Auto-generated method stub
    return null;
}
private Button btnAddAlarm;
private ListView lvListView;
private ArrayAdapter<AlarmData> adapter;

private static class AlarmData{
    public AlarmData(long time){
        this.time=time;
        date= Calendar.getInstance();
        timeLabel=String.format("%d月%d日 %d:%d", 
                date.get(Calendar.MONTH)+1,
                date.get(Calendar.DAY_OF_MONTH),
                date.get(Calendar.HOUR_OF_DAY),
                date.get(Calendar.MINUTE));

    }

    public long getTime() {
        return time;
    }

    public String getTimeLabel() {
        return timeLabel;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return getTimeLabel();
    }

    private String timeLabel="";
    private long time=0;
    private Calendar date;
}

private TabHost tabHost;


}
取消 提交回答
全部回答(0)
+关注
2
文章
9426
问答
问答排行榜
最热
最新
相关电子书
更多
OceanBase 入门到实战教程
立即下载
阿里云图数据库GDB,加速开启“图智”未来.ppt
立即下载
实时数仓Hologres技术实战一本通2.0版(下)
立即下载