0

新しい BetterPickers ライブラリ (日付と時刻のピッカー) をテストしています。xml ファイルに複数のボタンを追加するまでは、すべて問題ありません。ピッカーを介して選択した後のボタンテキストの時間の表示が停止されます。これは私のレイアウトxmlファイルです:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
         android:layout_height="?android:attr/listPreferredItemHeight"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/lieu_depart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lieu de prise en charge"
            style="" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="false"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/activity_vertical_margin" >

        <Button
            android:id="@+id/button2_date_depart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date" />

        <Button
            android:id="@+id/time_depart5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="settime" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minWidth="@dimen/activity_vertical_margin"
            android:text="Lieu de restitution" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout3"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button5_date_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date" />

        <Button
            android:id="@+id/button6_time_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="Heure" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout4"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/Button03"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Button" />

    </LinearLayout>
</RelativeLayout>
</ScrollView>

これが私のコードです:Reservation.java

package younga.ines.yourcar;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockFragment;
import com.doomonafireball.betterpickers.datepicker.DatePickerBuilder;
import com.doomonafireball.betterpickers.datepicker.DatePickerDialogFragment;
import com.doomonafireball.betterpickers.timepicker.TimePickerBuilder;
import com.doomonafireball.betterpickers.timepicker.TimePickerDialogFragment;


public class Reservation extends SherlockFragment implements OnClickListener,
DatePickerDialogFragment.DatePickerDialogHandler,
TimePickerDialogFragment.TimePickerDialogHandler {

private Button ti_depart;
private Button da_depart;
private Button ti_arrive;
private Button da_arrive;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    View rootView = inflater.inflate(R.layout.fragment_reservation, container, false);


    //date_depart
    da_depart=(Button)rootView.findViewById(R.id.button2_date_depart);
    da_depart.setOnClickListener(this);

    //time_depart
    ti_depart = (Button) rootView.findViewById(R.id.time_depart5);
    ti_depart.setOnClickListener(this);

    //date_arrive
    da_arrive=(Button)rootView.findViewById(R.id.button5_date_arrive);
    da_arrive.setOnClickListener(this);

    //time_arrive
    ti_arrive=(Button)rootView.findViewById(R.id.button6_time_arrive);
    ti_arrive.setOnClickListener(this);


    return rootView;    }


private void calltoDatedepartPicker() {
    // TODO Auto-generated method stub
    DatePickerBuilder dpb = new DatePickerBuilder()
    .setFragmentManager(getChildFragmentManager())
     .setStyleResId(R.style.BetterPickersDialogFragment)
    .setTargetFragment(Reservation.this);
    dpb.show();   
}
private void calltoTimedepartPicker() {
    // TODO Auto-generated method stub

    TimePickerBuilder tpb = new TimePickerBuilder()
    .setFragmentManager(getChildFragmentManager())
    .setStyleResId(R.style.BetterPickersDialogFragment)
    .setTargetFragment(Reservation.this);
    tpb.show();

}

private void calltoTimearrivePicker() {
    // TODO Auto-generated method stub
    TimePickerBuilder tpb = new TimePickerBuilder()
    .setFragmentManager(getChildFragmentManager())
    .setStyleResId(R.style.BetterPickersDialogFragment)
    .setTargetFragment(Reservation.this);
    tpb.show();

}


private void calltoDatearrivePicker() {
    // TODO Auto-generated method stub
    DatePickerBuilder dpb = new DatePickerBuilder()
    .setFragmentManager(getChildFragmentManager())
     .setStyleResId(R.style.BetterPickersDialogFragment)
    .setTargetFragment(Reservation.this);
    dpb.show();
}




@Override
public void onDialogTimeSet(int reference, int hourOfDay, int minute) {
    // TODO Auto-generated method stub
    // reference argument show -1 as value
    Toast.makeText(getSherlockActivity(), ""+reference, Toast.LENGTH_SHORT).show();
    if(reference==R.id.time_depart5) ti_depart.setText("" + hourOfDay + ":" + minute);
    if(reference==R.id.button6_time_arrive) ti_arrive.setText("" + hourOfDay + ":" + minute);
    }


@Override
public void onDialogDateSet(int reference, int year, int monthOfYear,
        int dayOfMonth) {
    // TODO Auto-generated method stub
    if(reference==R.id.button2_date_depart) da_depart.setText("" + dayOfMonth + "" + monthOfYear + "" + year);
    if(reference==R.id.button5_date_arrive) da_arrive.setText("" + dayOfMonth + "" + monthOfYear + "" + year);

}


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    if(v.getId()==R.id.button2_date_depart){
        calltoDatedepartPicker();

    }

    if(v.getId()==R.id.time_depart5){
        calltoTimedepartPicker();

    }

    if(v.getId()==R.id.button5_date_arrive){
        calltoDatearrivePicker();
    }

    if(v.getId()==R.id.button6_time_arrive){
        calltoTimearrivePicker();
    }




}

}

だから私の質問は、 onDialogDataSet および onDialogTimeSet メソッドを使用して、4 つのボタン で選択された時間または日付を表示する方法です????

PS: 1 つのボタンを使用するだけで非常にうまく機能します!! 前もって感謝します 。

4

1 に答える 1

0

フラグを使用して修正しました

@Override public void onDialogTimeSet ( int reference, int hourOfDay, int minute){
                if (flag_time_depart == true) {
                    ti_depart.setText("" + hourOfDay + ":" + minute);
                    flag_time_depart = false;
                }
                if (flag_time_arrive == true) {
                    ti_arrive.setText("" + hourOfDay + ":" + minute);
                    flag_time_arrive = false;
                }
            }
            and without forgetting the Flags declaration as globals vars:
            private boolean flag_time_depart = false;
            private boolean flag_time_arrive = false;

日付ピッカーの例

        DatePickerBuilder dpb = new DatePickerBuilder()
                .setFragmentManager(getChildFragmentManager())
                .setStyleResId(R.style.BetterPickersDialogFragment_Light)
                .setTargetFragment(Reserva.this);
        dpb.show();
于 2014-04-12T22:51:02.367 に答える