我有一个编辑字段,当我点击它时,日期选择器将打开,但我无法在第一次点击时弹出日期选择器。如果我第一次单击编辑字段,则不会出现日期选择器。当我第二次或第三次单击时,它正在显示。这是我的代码:
public class MainActivity extends Activity implements OnClickListener {
private Calendar calendar;
private int day;
private int month;
private int year;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
date = (EditText) findViewById(R.id.date);
calendar = Calendar.getInstance();
day = calendar.get(Calendar.DAY_OF_MONTH);
month = calendar.get(Calendar.MONTH);
year = calendar.get(Calendar.YEAR);
date.setOnClickListener(this);
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
return new DatePickerDialog(this, datePickerListener, year, month, day);
}
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int selectedYear, int …
Run Code Online (Sandbox Code Playgroud) 我试图从Android中的googleplus集成获取性别和生日...但是性别为"0"请帮我这个..我附上我的代码..请找下面的代码..生日显示为空...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mGoogleApiClient.connect();
}
});
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
}
protected void onStart() {
super.onStart();
// mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
startIntentSenderForResult(result.getResolution()
.getIntentSender(), RC_SIGN_IN, null, 0, 0, 0);
} …
Run Code Online (Sandbox Code Playgroud)