How to get handle to ImageView in a ListItem

by Hari » Fri, 30 Jul 2010 08:30:15 GMT


Sponsored Links
 Hi,
I have implemented a "EfficientAdapter". Each list item is a
LinearLayout of a combination of image and text views.  This
EfficientAdapter is attached to a Array<CustomObject>. Code snippet is
below:

[code]
public class ExampleList extends ListActivity {
  private class EfficientAdapter extends BaseAdapter {
    .........
      public View getView(int position, View convertView, ViewGroup
parent) {
           ..........
           //Make the ICON Clickable
          holder.icon.setOnClickListener(mCorkyListener);
      }

      class ViewHolder {
            ......
            TextView dateRange;
            ImageView icon;
            .....
        }
  }

  public void onCreate(Bundle savedInstanceState) {.....}

  protected void onListItemClick(ListView l, View v, int position,
long id) {.....}

  public OnClickListener mCorkyListener = new OnClickListener() {
        public void onClick(View v) {
                // do something when the button is clicked
                Log.i("Item ID", v.getId()+"");
                captureImage();
    }};

   .................
 }
[/code]

The captureImage() method brings up the option for user to select an
image from Gallery or click a snap.

My Problem:
"I DO NOT KNOW" how to get a handle to the image in the list item that
was clicked. I will have refresh the image view with what ever image
was selected by the user.

Any leads or pointers in resolving this issue is greatly appreciated

Thanks
Hari

--



How to get handle to ImageView in a ListItem

by Mark Murphy » Fri, 30 Jul 2010 08:32:23 GMT


 The View passed into onListItemClick() is the row. Call findViewById()
on that View to retrieve your ImageView.



>


Sponsored Links


How to get handle to ImageView in a ListItem

by Hari » Sat, 31 Jul 2010 06:45:56 GMT


 Hi Mark,
Thanks for the Reply.

I might have not stated my question properly.

I have implemented another functionality for onListItemClick().

Each list item has a ImageView and i want the user to be able to
change this image by selecting from phone's gallery or by taking a
snap. So i have an onClicklistener() for the image view. How can i
know which ListItem was clicked? I also would like to update the
database for this ListItem to save the image byte[] in blob column.
For this reason i have to know the item that was clicked.

Regards
Hari




> >



How to get handle to ImageView in a ListItem

by greg » Sat, 31 Jul 2010 07:26:32 GMT


 I also use the EfficientAdapter BaseAdapter in my ListView.  Is it not
possible for you to use the onItemClick handler, which provides the
list index (i.e., position), to implement your image change?  (That's
what I do.)






> > >



How to get handle to ImageView in a ListItem

by Hari » Sat, 31 Jul 2010 08:09:22 GMT


 i Greg,
I gave a thought to that approach as well. I want the image selection
dialog to come up only when the user clicks on the image view.

With onItemClick handler, the dialog pops up when user clicks any
section of the list item. How do i make sure that the dialog pops up
only when the user clickes on the Image.

Regards
Hari

On Jul 30, 7:26pm, greg <sep...@eduneer.com> wrote:
> > > >



How to get handle to ImageView in a ListItem

by greg » Sat, 31 Jul 2010 20:56:34 GMT


  haven't tried it, but perhaps another listener to detect the x
coordinate of the click? (The more complicated y coordinate could be
ignored if the image fills the row height.)


On Jul 30, 8:09pm, Hari <mba.for.d...@gmail.com> wrote:
> > > > >



Other Threads

1. Query the List of Favorite Contacts

Hi,

I'm trying to query the list of favorite contacts. I use the line
below:

Cursor cur = this.getContentResolver().query(People.CONTENT_URI, null,
People.STARRED + "=?", new String[] { "1" }, null);

However, this doesn't work because NULL data is returned, even though
my list of favorite contacts is not empty.

Is there a way to query the list of favorite contacts?

Thanks in advance,

Ali

-- 

2. crash in ListView.layoutChildren on display of onscreen keyboard

I also am getting a crash occasionally with this stack trace:

02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.AbsListView.obtainView(AbsListView.java:1266)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.ListView.makeAndAddView(ListView.java:1668)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.ListView.fillSpecific(ListView.java:1212)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.ListView.layoutChildren(ListView.java:1499)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.AbsListView.onLayout(AbsListView.java:1113)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.LinearLayout.onLayout(LinearLayout.java:918)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.View.layout(View.java:6830)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.ViewRoot.performTraversals(ViewRoot.java:996)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.os.Handler.dispatchMessage(Handler.java:99)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.os.Looper.loop(Looper.java:123)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
java.lang.reflect.Method.invokeNative(Native Method)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
java.lang.reflect.Method.invoke(Method.java:521)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-14 10:08:56.618: ERROR/AndroidRuntime(326):     at
dalvik.system.NativeStart.main(Native Method)

I am doing a pretty plain jane Cursor load of the List without any
threading:

protected void onCreate(Bundle savedState)
   {
           super.onCreate(savedState);

           ContentResolver cr = getContentResolver();

           String[] projection = new String[] { TrackHeader._ID,
TrackHeader.DESCRIPTION, TrackHeader.CREATION_TIME,
                                                                                
        TrackHeader.CATEGORY, TrackHeader.DURATION,
TrackHeader.DISTANCE,
                                                                                
        TrackHeader.POSTED };

           Cursor c = cr.query(TrackHeader.CONTENT_URI, projection, null,
null, null);
           startManagingCursor(c);

           TrackHeaderDataAdapter adapter = new TrackHeaderDataAdapter(this,
R.layout.track_list_item, mCursor, projection, null);
           setListAdapter(adapter);

Any ideas?

Tim





-- 

3. Broadcast Receiver without Activity.

4. Text To Speech Android 1.6 with minsdk 3

5. Smaller tabs, such as the Facebook official app

6. New sales have come to a halt Developer console stopped updating?

7. CyanogenMod 5.0 for Nexus One (STABLE) is out