未知错误,单击按钮时无操作

时间:2013-06-27 09:04:39

标签: android android-intent

似乎没有错误,但是当我按下pick_time Button时没有动作。仅供参考,我创建了两个标签,我想创建一个时间戳。我从http://www.lukehorvat.com/blog/android-time-picker-example/

获取了代码

请指教,谢谢。

来自logcat:

06-26 00:12:14.635: D/GestureDetector(7299): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0

我的主要活动代码:

package com.app.hi;


import java.util.Calendar;
import com.app.hi.TimePickerFragment.TimePickedListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.text.format.DateFormat;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends FragmentActivity {
    private FragmentTabHost mTabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.tabFrameLayout);

        mTabHost.addTab(
                mTabHost.newTabSpec("Create").setIndicator("Create",
                        getResources().getDrawable(R.drawable.ic_tab_create)),
                CreateTab.class, null);

        mTabHost.addTab(
                mTabHost.newTabSpec("View").setIndicator("View",
                        getResources().getDrawable(R.drawable.ic_tab_view)),
                ViewTab.class, null);


    }


    public class Main extends FragmentActivity implements TimePickedListener
    {
        private TextView mPickedTimeText;
        private Button mPickTimeButton;

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.view_layout);

            mPickedTimeText = (TextView) findViewById(R.id.text_picked_time);

            mPickTimeButton = (Button) findViewById(R.id.button_pick_time);
            mPickTimeButton.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    // show the time picker dialog
                    DialogFragment newFragment = new TimePickerFragment();
                    newFragment.show(getSupportFragmentManager(), "timePicker");
                }
            });
        }

        @Override
        public void onTimePicked(Calendar time)
        {
            // display the selected time in the TextView
            mPickedTimeText.setText(DateFormat.format("h:mm a", time));
        }
    }



}

TimePickerFragment代码:

package com.app.hi;

import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;

import java.util.Calendar;

public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener
{
    private TimePickedListener mListener;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        // use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        // create a new instance of TimePickerDialog and return it
        return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
    }

    @Override
    public void onAttach(Activity activity)
    {
        // when the fragment is initially shown (i.e. attached to the activity), cast the activity to the callback interface type
        super.onAttach(activity);
        try
        {
            mListener = (TimePickedListener) activity;
        }
        catch (ClassCastException e)
        {
            throw new ClassCastException(activity.toString() + " must implement " + TimePickedListener.class.getName());
        }
    }

    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute)
    {
        // when the time is selected, send it to the activity via its callback interface method
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, hourOfDay);
        c.set(Calendar.MINUTE, minute);

        mListener.onTimePicked(c);
    }

    public static interface TimePickedListener
    {
        public void onTimePicked(Calendar time);
    }
}

请参考并回复我。

0 个答案:

没有答案
相关问题