[android-developers] Object reference changes value seemingly at random

2010-07-14 Thread Jonhoo
Hey hey!

I've just started developing my second Android application. It is
pretty straightforward, but useful nonetheless.
All it does is allow the user to record key-value pairs for later
reference (for things you can't be bothered to remember such as bank
account numbers, PGP fingerprints, etc..)

While doing this, however, I have been completely stumped by a bug..:
I'll try to explain as best I can.
My main, and only, activity extends ListActivity, and each element in
the list is a LinearLayout containing two TextViews, one with the key
and the other with the value.
The main class (Tuples) holds a pointer called activeElement, which
points to the latest element to have been either clicked or long
clicked.
--
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView? parent, View view, int
position, long id) {
Tuples.this.activeElement = (LinearLayout) view;
// More code...
--

Furthermore, I have three dialogs, one which shows details for a list
item when clicked, one which opens a simple select list of Edit or
Delete on long click, and finally, an edit dialog (which also serves
as a new element dialog).
At this point, the logic for editing things is very simple: When an
element is edited, its old row is deleted, and a new one is created
with the new values.

The code reads as follows (this is on the AlertDialog.Builder I use to
build the dialog in onCreateDialog):
--
.setPositiveButton(R.string.save, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Save!
AlertDialog ad = (AlertDialog) dialog;
EditText tk = (EditText) ad.findViewById(R.id.tuple_key);
EditText tv = (EditText) ad.findViewById(R.id.tuple_value);

// Delete old one
Tuples.this.deleteElement ( Tuples.this.activeElement );

// Add new one
Tuples.this.add ( tk.getText().toString(),
tv.getText().toString() );
}
})
--

Here comes the really weird part though - when I run the program,
everything works fine, except that on edit, it is not the element I
long click on that is deleted, but the last element in list?
I have put debugging statements all over the place, and it seems as
though it changes value just before the onClick on the dialog OK
button is clicked.
The variable is not changed anywhere in my code (I have put debugging
statements on all activeElement = statements), and at the end of
onPrepareDialog, activeElement points to the correct element.
Can anyone think of what might be causing this? I'll provide more code
if needed.

Hope for a helpful answer =)
Jon

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Using the internal NumberPicker widget

2009-10-11 Thread Jonhoo

Hello all androids!
I am developing an application in which I want the user to input the
duration of a given item, something which the vertical spinners used
for DatePicker and TimePicker would be ideal for. However, after
looking into this, it seems that the widget both of these depend on,
NumberPicker, is an internal class
( com.android.internal.widget.NumberPicker ) not available through the
normal API.
What is the reasoning behind keeping this very useful widget internal?
Is there any way besides cloning the source ( which I couldn't get to
work anyway.. Eclipse told me that R.layout was not available... ) and
using com.android.internal.widget.NumberPicker directly as the view in
the layout XML ( which doesn't seem to be working properly either
( java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.speechmark/com.speechmark.SpeechMarkEdit}:
java.lang.ClassCastException:
com.android.internal.widget.NumberPicker )?

Jon

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---