时间选择器

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/time_line1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#A7c0dc"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="20px" >

        <NumberPicker
            android:id="@+id/number"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:layout_weight="3" />

        <TimePicker
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/time_cancel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="@drawable/dialog_btn_right_checked"
            android:text="取消"
            android:textColor="#fff" />

        <Button
            android:id="@+id/time_ok"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="@drawable/dialog_btn_right_checked"
            android:text="确认"
            android:textColor="#fff" />
    </LinearLayout>

</LinearLayout>

activity

package com.yunkun.inner_fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.yunkun.activity.AdressActivity;
import com.yunkun.activity.R;
import com.yunkun.activity.SongActivity;
import com.yunkun.popup.MyPopupWindow;

public class SendFrag extends Fragment implements OnClickListener {
    private Button mOrder;
    private RelativeLayout mStartadr;
    private RelativeLayout mEndadr;
    private RelativeLayout mGetgoodstime;
    public static TextView helpsend_getgoodstime;
    TextView mFreetext;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // 找控件;
        View view = inflater.inflate(R.layout.send_fragmnet, null);
        findViewById(view);
        Listener();

        return view;
    }

    // 找控件;
    private void findViewById(View view) {
        mStartadr = (RelativeLayout) view.findViewById(R.id.helpsend_rel1);

        mEndadr = (RelativeLayout) view.findViewById(R.id.helpsend_rel2);

        mGetgoodstime = (RelativeLayout) view.findViewById(R.id.helpsend_rel4);
        helpsend_getgoodstime = (TextView) view
                .findViewById(R.id.helpsend_getgoodstime);
        mFreetext = (TextView) view.findViewById(R.id.helpsend_freeperson);
        mOrder = (Button) view.findViewById(R.id.helpsend_order);
    }

    // 设置监听
    public void Listener() {
        mStartadr.setOnClickListener(this);
        mEndadr.setOnClickListener(this);
        mGetgoodstime.setOnClickListener(this);
        mFreetext.setOnClickListener(this);
        mOrder.setOnClickListener(this);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        // 点击跳转之地图
        case R.id.helpsend_rel1:
            Intent intent1 = new Intent(getActivity(), AdressActivity.class);
            intent1.putExtra("property", "2");
            startActivity(intent1);
            break;
        case R.id.helpsend_rel2:
            Intent intent2 = new Intent(getActivity(), AdressActivity.class);
            intent2.putExtra("property", "3");
            startActivity(intent2);

            break;

        // 显示取货时间;
        case R.id.helpsend_rel4:
            new MyPopupWindow(getActivity(), null, v);

            break;
        case R.id.helpsend_freeperson:

            break;
        case R.id.helpsend_order:
            startActivity(new Intent(getActivity(),SongActivity.class));
            break;
        }
    }
    // @Override
    // public void onActivityResult(int requestCode, int resultCode, Intent
    // data) {
    // // TODO Auto-generated method stub
    // super.onActivityResult(requestCode, resultCode, data);
    // }
}

原文地址:https://www.cnblogs.com/weiyangge/p/5479578.html