ListView: onListItemClick and On Touch

My app starts with an empty list and user has to click “Add” to create a first item.  First time users can’t figure out the Add (plus sign) button and they smack the finger on a blank screen, maybe something will come up to guide. Ok that’s a task: when user touches empty area on a list we want to treat it as Add button was clicked. 

My activity already implements onListItemClick and it’s void call

There is onTouch which is boolean. Let’s try

public boolean onTouch(View arg0, MotionEvent event) {

Log.d(TAG, “onTouch list”);

boolean ret=false;
return ret;

Simple enough though this is called 3 times when I touch once. 

Reading. I see, there are 3 event. I’ll handle the Action Up.

case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
// code
case MotionEvent.ACTION_UP:
if (lView.getAdapter().getCount()<=0){

This sounds simple but I spent some time figuring what the condition is for me to return true and when to return false, so that onListItemClick is still called. Ended up limiting this feature to a condition when list has no items. 

Good enough. 

Take care.

Going to read release procedures next. 

Please Don't Touch

Please Don’t Touch (Photo credit: Wikipedia)




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s