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