[android-developers] How can I keep dynamic views focused through an orientation change?

2010-11-09 Thread CodeFusion
If I have a layout with lots of EditText views in a LinearLayout and
the user focuses the third one down and flips out the keyboard to
start typing, the entire layout is destroyed and recreated through the
activity lifecycle.  When everything is done, however, the third
EditText is given focus again and the user never knows that anything
happened and types away.

I am creating a similar layout, but due to the nature of my data, I
have to dynamically create the list of EditTexts, mixed with some
other views. The default layout has one EditText at the top, a
ScrollView with a LinearLayout child (which will be filled with
EditTexts later), and some action buttons at the bottom.  Then I fill
the LinearLayout with all the EditText fields I need (based on extras
passed via intent).

This part works quite well, but the way the activty handles Runtime
Configuration changes is broken now (from a UI perspective).  Now if
the user focuses the third EditText (which was dynamically created via
new EditText()) and flips out the keyboard, the layout is destroyed
and recreated, but focus is always given to the permanent EditText at
the top of the screen.

Is there something I need to do when adding my dynamic views to make
sure they can keep focus through orientation changes?  Or is there a
way I can work around the issue and force focus to be given to the
last view that had it before the change?

-- 
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] How could I be interfering with context menu longclick?

2010-10-04 Thread CodeFusion
My app used to use a standard ListView, and
registerForContextMenu(getListView()) and everything worked just fine.

I needed to change my app to accommodate nested lists so I replaced
the ListView with ExpandableListView. I changed the Activity to
ExpandableListActivity. I also changed my adapter to a tree adapter
and implemented a custom view class to populate the list with (based
on a LinearLayout viewgroup).

I have been trying to track down where I screwed it up and I've found
several things.

The most important is that when I add a longclick listener to my
custom view and return false from it, my context menu pops up and
functions properly.  However, I don't get the fading orange-to-white
long click animation because the long click is being sucked up
somewhere else until it is handled by a longclicklistener and ignored
(thus being thrown back up the chain until it reaches the
ExpandableListView (which is registered for context menus).

I am using a TouchInterceptor model to handle certain gestures from my
listview with the following implementation:

public class TouchInterceptor extends ExpandableListView {
...
protected MotionEvent downStart = null;

public boolean onInterceptTouchEvent(MotionEvent event) {

switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
// keep track of the starting down-event
downStart = MotionEvent.obtain(event);
break;
case MotionEvent.ACTION_MOVE:
// if moved horizontally more than slop*2, capture the 
event for
ourselves
if(downStart == null)
{
break;
}
float deltaX = event.getX() - downStart.getX();
if(Math.abs(deltaX)  ViewConfiguration.getTouchSlop() 
* 2)
return true;
break;
}

// otherwise let the event slip through to children
return super.onInterceptTouchEvent(event);
}

public boolean onTouchEvent(MotionEvent event) {

// check if we crossed an item
if(downStart != null)
{
float targetWidth = this.getWidth() / 4;

float deltaX = event.getX() - downStart.getX(),
deltaY = event.getY() - downStart.getY();

boolean movedAcross = (Math.abs(deltaX)  targetWidth);
boolean steadyHand = (Math.abs(deltaX / deltaY)  2);

if(movedAcross  steadyHand) {
boolean crossRight = (deltaX  0);

// figure out which child view we crossed
ListView list = 
(ListView)this.findViewById(android.R.id.list);
int position = 
list.pointToPosition((int)downStart.getX(),
(int)downStart.getY());

// pass crossed event to any listeners
onCross(crossRight, position);
downStart = null;
// and return true to consume this event
return true;
}
}
return super.onTouchEvent(event);
}
...
}


Is there something wrong with how I'm handling these events?


Note: although my context menu pops up, it only does so when the long-
click event is triggered, not a long OK button click.

Something is screwed up here and I'm not sure how to track it down.

-- 
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] Where should I change a ListView's backing data from?

2010-07-13 Thread CodeFusion
I have a ListView that is filled from my adapter with my custom
views.  Each view has two buttons, one that starts another activity to
edit the contents of that list item and one to delete that item.

My question is where should my ClickEvent handlers for those buttons
be?  Should I put them right in my custom view code since I have all
the information I need? Should I start an ASyncTask that deletes the
item and updates the adapter data and calls onDataSetChanged() etc?

Should all of this be bubbled up through events to my ListActivity?

I could probably make it work at any level, but at what level along
this hierarchy (Activity-ListView-Adapter-ListItemView) is the
proper place to edit/delete backing data for the ListView?

-- 
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