0
所以我想要一個時間和日期選取器彈出,當我點擊一個按鈕看谷歌日曆時,你按下右下方的晶圓廠按鈕。將會有一個新窗口顯示日期和時間,當你點擊其中一個選擇器打開時。點擊日期選擇器(如谷歌日曆)
林不知道如果我需要創建一個片段與時間選擇器在其中,只是使尺寸更小或如果我必須通過代碼創建一個。
這是我的代碼:
public class NewEventActivity extends AppCompatActivity {
private LayoutInflater inflater;
private String[] arraySpinner;
private Button date_from;
private Button date_to;
private Button time_from;
private Button time_to;
private EditText title;
private EditText invite;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_event_fragment);
findviewbyids();
initPickers();
}
public void findviewbyids(){
date_from = (Button) findViewById(R.id.bt_date_from);
time_from = (Button) findViewById(R.id.bt_time_from);
date_to = (Button) findViewById(R.id.bt_date_to);
time_to = (Button) findViewById(R.id.bt_time_to);
title = (EditText) findViewById(R.id.et_title);
invite = (EditText) findViewById(R.id.et_invite);
}
public void initPickers(){
Date today = new Date();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
DateFormat tf = new SimpleDateFormat("HH:mm:ss");
String reportDate = df.format(today);
String reportTime = tf.format(today);
date_from.setText(reportDate);
time_from.setText(reportTime);
date_to.setText(reportDate);
time_to.setText(reportTime);
date_from.setVisibility(View.VISIBLE);
date_to.setVisibility(View.VISIBLE);
time_from.setVisibility(View.VISIBLE);
time_to.setVisibility(View.VISIBLE);
date_from.setBackgroundColor(Color.TRANSPARENT);
date_to.setBackgroundColor(Color.TRANSPARENT);
time_from.setBackgroundColor(Color.TRANSPARENT);
time_to.setBackgroundColor(Color.TRANSPARENT);
Spinner group = (Spinner) findViewById(R.id.sp_group);
this.arraySpinner = new String[] {
"1", "2", "3", "4", "5"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, arraySpinner);
group.setAdapter(adapter);
date_from.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
現在
當我在date_from按鈕一個datepicker應該出現設定日期後點擊它應該覆蓋上date_from文本
我希望你明白我的意思
@zooky你解決了你的問題嗎? – Saveen