Re: [android-developers] Re: ListView: responding to item clicks via a listener

2011-09-21 Thread Streets Of Boston
Try not to do this. It will break the UI model that Android users expect on 
their phones.
However, if you really need it:

1. Modify the data items that are handled by your ListView's adapter. Add an 
field that could tell how many times a list-item has been clicked (e.g. 
numberOfClicks).

2. Handle the onItemClick(...) (or in your case 'onClick(...)') as follows:
MyDataItem item = adapter.getItem(position);
Increase the item.numberOfClicks. 
If it becomes 1: do nothing.
If it becomes 2: go to the other screen and re-set item.numberOfClicks to 0.
(Be sure to call adapter.notifyDatatSetChanged()).

3. Change the 'getView()' method of your ListView's adapter:
MyDataItem item = getItem(position);
If the corresponding's item.numberOfClicks is 1, then color the background 
of that item in a particular color (that would indicate a 'highlight').
If the corresponding's item.numberOfClicks is not 1, then make the 
background of that item transparent (android.R.color.transparent).


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

Re: [android-developers] Re: ListView: responding to item clicks via a listener

2011-09-20 Thread John Goche
Hello,

I am having a slight problem with my approach. When a row is highlighted
orange and
I click on it the orange highlighting goes away. But I want it to stay as I
want taps to

1. highlight the row on the first tap
2. take to a second screen on the second tap

Is this possible?

Thanks,

John Goche

On Mon, Sep 19, 2011 at 6:32 PM, John Goche johngoch...@googlemail.comwrote:


 On Mon, Sep 19, 2011 at 5:32 PM, Streets Of Boston 
 flyingdutc...@gmail.com wrote:

 The solution you have may work, but it's not the best... keyboard/dpad
 navigation of your list won't work well.

 My question is:
 What about  R.layout.alarmgroups_item. Could you show the
 alarmgroups_item.xml contents? Maybe one of the items in there is clickable
 and/or focusable.


 Well, here is all I have in the file at the moment. Just a bunch of text
 views. The idea is that the user can click them
 to highlight them and then push a button to take the user to another
 screen. How can I improve things
 then if that is not the best solution?

 Thanks for your help,

 John Goche
 SimpleAdapter adapter = new SimpleAdapter(this, maps,
 R.layout.alarmgroups_item, from, to) {
   @Override
   public View getView(int position, View convertView, ViewGroup parent)
 {
 View view = super.getView(position, convertView, parent);
 // view.setOnClickListener(
 AlarmGroupsActivity.this);
 view.setOnClickListener(new OnClickListener() {

   public void onClick(View arg0) {
 Toast.makeText(getApplicationContext(), clicked,
 Toast.LENGTH_SHORT).show();
   }
 });
 return view;

   }
 };

 listView.setAdapter(adapter);


 ?xml version=1.0 encoding=utf-8?
 LinearLayout
   xmlns:android=http://schemas.android.com/apk/res/android;
   android:orientation=vertical
   android:layout_width=fill_parent
   android:layout_height=fill_parent
   LinearLayout
 android:layout_width=match_parent
 android:layout_height=wrap_content
 TextView
   android:id=@+id/one
   android:layout_height=wrap_content
   android:layout_width=200dp
 /TextView
 TextView
   android:id=@+id/two
   android:layout_weight=1
   android:layout_width=wrap_content
   android:layout_height=wrap_content
   android:inputType=time
 /TextView
   /LinearLayout
   LinearLayout
 android:layout_width=match_parent
 android:layout_height=wrap_content
 TextView
   android:id=@+id/three
   android:layout_height=wrap_content
   android:layout_width=200dp
 /TextView
 TextView
   android:id=@+id/four
   android:layout_weight=1
   android:layout_width=wrap_content
   android:layout_height=wrap_content
   android:inputType=time
 /TextView
   /LinearLayout
   TextView
 android:id=@+id/five
 android:layout_height=wrap_content
 android:layout_width=match_parent
   /TextView
 /LinearLayout


-- 
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] Re: ListView: responding to item clicks via a listener

2011-09-19 Thread John Goche
Hello,

The solution was to attach an onItemClick listener to each list item rather
than to the
ListView itself like so:

SimpleAdapter adapter = new SimpleAdapter(this, maps,
R.layout.alarmgroups_item, from, to) {
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
// view.setOnClickListener(AlarmGroupsActivity.this);
view.setOnClickListener(new OnClickListener() {

  public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), clicked,
Toast.LENGTH_SHORT).show();
  }
});
return view;

  }
};

listView.setAdapter(adapter);


--
Regards,

John Goche


On Mon, Sep 19, 2011 at 4:27 PM, John Goche johngoch...@googlemail.comwrote:


 Hello,

 I am trying to respond to item clicks in a ListView which has an adapter.
 When
 the items are clicked (each item is just a LinearLayout with four
 TextViews),
 my onItemClick listener is not called even though my ListView is clickable
 and focusable. I have read the following but was no help to me:


 http://stackoverflow.com/questions/4742611/android-onitemclick-silently-fails

 Anyone have any ideas?

 Thanks,

 John Goche


-- 
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] Re: ListView: responding to item clicks via a listener

2011-09-19 Thread Streets Of Boston
The solution you have may work, but it's not the best... keyboard/dpad 
navigation of your list won't work well.

My question is:
What about  R.layout.alarmgroups_item. Could you show the 
alarmgroups_item.xml contents? Maybe one of the items in there is clickable 
and/or focusable.

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

Re: [android-developers] Re: ListView: responding to item clicks via a listener

2011-09-19 Thread John Goche
On Mon, Sep 19, 2011 at 5:32 PM, Streets Of Boston
flyingdutc...@gmail.comwrote:

 The solution you have may work, but it's not the best... keyboard/dpad
 navigation of your list won't work well.

 My question is:
 What about  R.layout.alarmgroups_item. Could you show the
 alarmgroups_item.xml contents? Maybe one of the items in there is clickable
 and/or focusable.


Well, here is all I have in the file at the moment. Just a bunch of text
views. The idea is that the user can click them
to highlight them and then push a button to take the user to another screen.
How can I improve things
then if that is not the best solution?

Thanks for your help,

John Goche

?xml version=1.0 encoding=utf-8?
LinearLayout
  xmlns:android=http://schemas.android.com/apk/res/android;
  android:orientation=vertical
  android:layout_width=fill_parent
  android:layout_height=fill_parent
  LinearLayout
android:layout_width=match_parent
android:layout_height=wrap_content
TextView
  android:id=@+id/one
  android:layout_height=wrap_content
  android:layout_width=200dp
/TextView
TextView
  android:id=@+id/two
  android:layout_weight=1
  android:layout_width=wrap_content
  android:layout_height=wrap_content
  android:inputType=time
/TextView
  /LinearLayout
  LinearLayout
android:layout_width=match_parent
android:layout_height=wrap_content
TextView
  android:id=@+id/three
  android:layout_height=wrap_content
  android:layout_width=200dp
/TextView
TextView
  android:id=@+id/four
  android:layout_weight=1
  android:layout_width=wrap_content
  android:layout_height=wrap_content
  android:inputType=time
/TextView
  /LinearLayout
  TextView
android:id=@+id/five
android:layout_height=wrap_content
android:layout_width=match_parent
  /TextView
/LinearLayout

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