I am a self-taught beginner and appreciate patience! Thanks!
In Eclipse, I made a custom alertdialog with its own xml file ("custom_dialog") and it is called "usernamealert".
I want an alert to pop-up if the user hasn't entered a username yet (ie, username.length == 0).
Inside this layout I have a textView ("What is your name?"), editText and button ("usernameButton").
Before putting in the onclicklistener for the button, everything worked. This was my (relevant) Java:
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) getCurrentFocus());
AlertDialog.Builder usernamebuilder = new AlertDialog.Builder(this);
usernamebuilder.setView(dialoglayout);
AlertDialog usernamealert = usernamebuilder.create();
When I put the onclicklistener in, it broke! Where should I have put it?
(the following is what I had tried... all in my OnCreate)
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.custom_dialog, (ViewGroup)getCurrentFocus());
AlertDialog.Builder usernamebuilder = new AlertDialog.Builder(this);
usernamebuilder.setView(dialoglayout);
Button usernameButton = (Button) usernamealert.findViewById(R.id.usernameButton);
usernameButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//store username in sharedprefs
usernamealert.dismiss();
}
});
After the code I said:
if (username.length() == 0) {
usernamealert.show();
}
Again, it worked before I started messing with the button!!
It is needed to specify where will the code search the button, if its only "findViewById" it would search in the xml of the host, it should be
This is part of my class, Hireteachernegotiate.class, which has a layout of hireteachernegotiate.xml
This is the dialog layout
Try this.
See if that works, or if it helps in some way.