Reputation: 1610
So I create a custom dialog where I set it to an xml file. In that file I have 2 buttons. One of them is responding to it's onClick counterpart where the other one isn't. I have NO idea why it isn't. I've set it's ID correctly, and done everything exactly the same way I did the other button... it's not giving me any errors, it's just not doing ANYTHING. I even set the button attribute "clickable" to true... I'm out of ideas.
Furthermore, it seems that if I try to add another button it also is unresponsive when clicked... is there some limit to the amount of widgets a dialog can take? lol...
it's the SaveAndFinish button that isn't working
Dialog createFlashCards = new Dialog(FlashCard.this);
createFlashCards.setContentView(R.layout.flash_card_create);
final EditText Question = (EditText)createFlashCards.findViewById(R.id.FlashCard_CreateQuestionEditText);
final EditText Answer = (EditText)createFlashCards.findViewById(R.id.FlashCard_CreateAnswerEditText);
Button SaveFlashCard = (Button)createFlashCards.findViewById(R.id.create_new_saved_FlashCard);
Button FinishAndSave = (Button)createFlashCards.findViewById(R.id.finish_creating_flashCards);
//saves the flashCard to the file on their phone
SaveFlashCard.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//have to check for empty questions or answers
if (!Question.getText().toString().equals("") && !Answer.getText().toString().equals("")) {
String newLineQuestionFixer = Question.getText().toString();
String newLineAnswerFixer = Answer.getText().toString();
newLineQuestionFixer = newLineQuestionFixer.replaceAll("\n", "<GAR>");
newLineAnswerFixer = newLineAnswerFixer.replaceAll("\n", "<GAR>");
Statics.addDataIntoFlashCardFile(FlashCard.this, input.getText().toString(), newLineQuestionFixer,
newLineAnswerFixer, Statics.mainPageListPosition);
Toast.makeText(FlashCard.this, "FlashCard successfully created", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(FlashCard.this, "Must have a question and an answer to save a flashCard", Toast.LENGTH_SHORT).show();
}
Question.setText("");
Answer.setText("");
}
});
FinishAndSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//have to check for empty questions or answers
if (!Question.getText().toString().equals("") && !Answer.getText().toString().equals("")) {
String newLineQuestionFixer = Question.getText().toString();
String newLineAnswerFixer = Answer.getText().toString();
newLineQuestionFixer = newLineQuestionFixer.replaceAll("\n", "<GAR>");
newLineAnswerFixer = newLineAnswerFixer.replaceAll("\n", "<GAR>");
Statics.addDataIntoFlashCardFile(FlashCard.this, input.getText().toString(), newLineQuestionFixer,
newLineAnswerFixer, Statics.mainPageListPosition);
Toast.makeText(FlashCard.this, "FlashCard successfully created", Toast.LENGTH_SHORT).show();
//just an intent to refresh the class
Intent refresh = new Intent(FlashCard.this, FlashCard.class);
refresh.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(refresh);
overridePendingTransition(0,0);
}
else {
Toast.makeText(FlashCard.this, "Must have a question and an answer to save a flashCard", Toast.LENGTH_SHORT).show();
}
}
});
createFlashCards.show();
here is the declaration of the buttons in xml
<Button
android:id="@+id/finish_creating_flashCards"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/btn_round_xml"
android:textColor="#FFFFFF"
android:clickable="true"
android:text="Finish and Save" />
<Button
android:id="@+id/create_new_saved_FlashCard"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/btn_round_xml"
android:clickable="true"
android:text="Save_FlashCard"
android:textColor="#FFFFFF" />
Upvotes: 0
Views: 162
Reputation: 1964
Can you try to catch click event like this:
<Button
android:id="@+id/finish_creating_flashCards"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/btn_round_xml"
android:textColor="#FFFFFF"
android:clickable="true"
android:text="Finish and Save"
android:onClick="finishCreatingFlashCards" />
In your .java code file:
public void finishCreatingFlashCards(View v) {
// your code on button click.
}
Upvotes: 1