2015-12-01 41 views
-1

如何禁用並排DatePicker顯示在我的活動(運行於KitKat/ Android 4.4,我使用Sony Xperia來運行它),我一直在努力尋找這一個,左側包含滾動部分和右側包含全壓光機,我想只顯示全壓光機:禁用並排DatePicker

enter image description here

import java.util.Calendar; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.DatePicker; 
import android.widget.TextView; 

public class versi2 extends Activity { 
    private TextView textViewTanggal; 
    private DatePicker datePicker; 
    private int year; 
    private int month; 
    private int day; 

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

    } 

    // display current date 
    public void setCurrentDateOnView() { 

     textViewTanggal = (TextView) findViewById(R.id.tvDisplayDate); 
     datePicker = (DatePicker) findViewById(R.id.dpResult); 

     final Calendar c = Calendar.getInstance(); 
     year = c.get(Calendar.YEAR); 
     month = c.get(Calendar.MONTH); 
     day = c.get(Calendar.DAY_OF_MONTH); 

     // set current date into textview 
     textViewTanggal.setText(new StringBuilder() 
       // Month is 0 based, just add 1 
       .append(month + 1).append("-").append(day).append("-") 
       .append(year).append(" ")); 

     datePicker.init(year, month, day, dateSetListener); 
    } 


    private DatePicker.OnDateChangedListener dateSetListener = new DatePicker.OnDateChangedListener() { 

     public void onDateChanged(DatePicker view, int year, int monthOfYear, 
            int dayOfMonth) { 
      textViewTanggal.setText(new StringBuilder() 
        // Month is 0 based, just add 1 
        .append(dayOfMonth + 1).append("-").append(monthOfYear).append("-") 
        .append(year).append(" ")); 

     } 
    }; 
} 

和佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

.... 
.... 
    <DatePicker 
     android:id="@+id/dpResult" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
+0

你想要什麼呢? –

+0

要麼@ Tanis.7x –

+2

...當然你從閱讀文檔開始了? ...不是? ...爲什麼?似乎有幾個第一屬性是你想要的 – Selvin

回答

2

DatePicker有一個datePickerMode屬性。使用android:datePickerMode="calendar"只顯示日曆。

+0

謝謝@ Tanis.7x,我會尋找。 –

+0

如果沒有'android:spinnersShown =「false」',它將無法正常工作,但非常感謝! –