如果我運行這個,不幸的是該應用程序已關閉。 但我嘗試了很多,我無法在文本字段中獲取日期。 showdialog存在錯誤, 它返回添加超級報警。 Datepicker沒有運行?
package com.task.reminder;
import java.util.Calendar;
import android.*;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
@SuppressWarnings("unused")
public class Add extends Activity
{
static final int DATE_ID = 0;
private int tMonth;
private int tYear;
private int tDay;
private EditText et2 =(EditText)findViewById(R.id.editText2);
private Button datebut=(Button)findViewById(R.id.button3);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
getdate();
}
private void getdate()
{
datebut.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v)
{
showDialog(DATE_ID);
}
});
final Calendar c = Calendar.getInstance();
tYear = c.get(Calendar.YEAR);
tMonth = c.get(Calendar.MONTH);
tDay = c.get(Calendar.DAY_OF_MONTH);
displaydate();
}
protected Dialog onCreateDialog(int id)
{
switch(id)
{
case DATE_ID:
return new DatePickerDialog(this, datePickerListener,
tYear, tMonth,tDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener=
new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth)
{
tYear=year;
tMonth=monthOfYear;
tDay=dayOfMonth;
displaydate();
}
};
private void displaydate()
{
et2.setText(new StringBuilder().append(tMonth+1).append("-").append(tDay).append("-").append(tYear).append(" "));
}
}
我需要一些幫助,感謝烏拉圭回合的貢獻。
改變的是,獲得了同樣的問題, – AndRaGhu
在logcat中,11月12日至四日後:02:05.035:d/gralloc_goldfish(721):無仿真器檢測到GPU仿真。 – AndRaGhu
@AndRaGhu:這是另一個問題,不編程有關看到這篇文章http://stackoverflow.com/questions/9323371/emulator-without-gpu-emulation-detected –