i am getting
09-20 12:42:26.697: ERROR/AndroidRuntime(721): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dashboardnew/com.dashboardnew.GmailFetchActivity}: java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 1
exception in 2.1 and lower versions.
@Override
protected Dialog onCreateDialog(int id) {
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alertdialog_gmail, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Gmail login");
alert.setMessage("Enter your username and password");
// Set an EditText view to get user input
alert.setView(textEntryView);
final EditText username = (EditText) textEntryView.findViewById(R.id.edit_username);
final EditText password = (EditText) textEntryView.findViewById(R.id.edit_password);
alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String user=username.getText().toString();
String pass=password.getText().toString();
new FetchGmail().execute(user+"@gmail.com",pass);
progressDialog2.show();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
pu开发者_运维技巧blic void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
// TODO Auto-generated method stub
return super.onCreateDialog(id);
}
Try this:
return alert.create();
instead of:
alert.show();
// TODO Auto-generated method stub
return super.onCreateDialog(id);
protected Dialog onCreateDialog (int id, Bundle args)
This method is deprecated. Use the new DialogFragment class with FragmentManager instead; this is also available on older platforms through the Android compatibility package. Callback for creating dialogs that are managed (saved and restored) for you by the activity. The default implementation calls through to onCreateDialog(int) for compatibility. If you are targeting HONEYCOMB or later, consider instead using a DialogFragment instead.
http://developer.android.com/reference/android/app/Activity.html#onCreateDialog%28int,%20android.os.Bundle%29
May be this code may help you...
Builder pinBuilder = new AlertDialog.Builder(context);
pinBuilder.setView(pinHolder).setTitle("Title")
.setMessage("Set Message")
.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
}
}).
setNegativeButton("Cancel",new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog,int which)
{
}
}).show();
Try alert.create().show();
Report back, if it didn't work.
may be this code may help you. First create class that extends dialog and then from your activity call this
CustomizeDilogForAddPhoto customizeDialog = new CustomizeDilogForAddPhoto(conntext,activity);
customizeDialog.show();
Here is your Dialog Class
public class CustomizeDilogForAddPhoto extends Dialog implements OnClickListener
{
public CustomizeDilogForAddPhoto(Context context,Activity activity)
{
super(context);
this.context=context;
this.activity=activity;
this.mainActivityname=maintabactivity;
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(android.R.style.Theme_Translucent_NoTitleBar);
/** Design the dialog in main.xml file */
setContentView(R.layout.custume_add_photo_dilog);
btnClose.setOnClickListener(this);
btnGallary.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
}
}
精彩评论