I had a major problem trying to set up an OnClickListener and
some buttons. When I included the following code with the last line
included, not commented out as it is here, the app would always crash
at run time. Often there would be problems with the compile process as
well. If I commented out the first four lines, where I set up data in
an ArrayList, the app didn't crash. I could have one or another but
not both. This was in the onCreate method.
Then I moved the buttons and onClickListener out of onCreate
and into another method. This solved the problem. Just for interest I
put a copy of the first four code lines into the same method and it
doesn't crash. It seems that the two things are not compatible in the
onCreate method.
My problem is solved with this knowledge, but it was hard
earned knowledge. I would be interested to know why this was
happening. Is it something I wasn't aware of, or is it a bug in
Android? Also I would like to save anyone trying to do a similar thing
from the struggle of finding out that these two things can't coexist
in onCreate.
todoItems = new ArrayList<ToDoItem>();
int resID = R.layout.todolist_item;
aa = new ToDoItemAdapter(this, resID, todoItems);
myListView.setAdapter(aa);
end_button = (Button)findViewById(R.id.end_button);
cards_button = (Button)findViewById(R.id.cards_button);
// end_button.setOnClickListener(new Button.OnClickListener()
{ public void onClick (View v){ calculate(); }});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---