set an OnClickListener for each button in a ListView's row

by Pzikit Bloo » Fri, 18 Apr 2008 15:13:39 GMT


Sponsored Links
 Hi guys,

I'm trying to create a ListView, with a TextView and two ImageButton
per row. The problem comes when I try to add an OnClickListener to
each button. I did in this way:

-- row.xml --
 <LinearLayout ....... >
   <TextView ...........  />
   <ImageButton
        android:id="@+id/button1"
        android:layout_width="35dip"
        android:layout_height="35dip"
        android:src="@android:drawable/arrow_down_panel_bezel" />
    <ImageButton ...... />
  </LinearLayout>

-- .java --
  .......
  ImageButton ib1 = (ImageButton) this.findViewById(R.id.button1);
  ib1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
                ........
        }
   });

But I get a NullPointerException.
What's the right way to do that?

Thanks,
Pzikit Bloo
--~--~---------~--~----~------------~-------~--~----~



set an OnClickListener for each button in a ListView's row

by Megha Joshi » Fri, 18 Apr 2008 23:32:32 GMT


 Hi,

You cannot set the listeners for your ListView's items in the Activity's
onCreate(), you should set the OnClickListeners inside the getView() method
of your List's adapter.

Thanks,
Megha





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


set an OnClickListener for each button in a ListView's row

by xingye » Mon, 21 Apr 2008 04:03:10 GMT


 see  http://code.google.com/p/sharepath ChooseBuddy.java. the multi- 
selected list is seem to yours.



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. setRepeatingAlarm on a loop

im trying to build an alarm within my app with codes like below but it
does not work with a loop having multiple days.

it seems like setRepeatingAlarm can not be fired with multiple
triggerAtTime values. it only works to repeat the alarm with one
TiggeratTime and an interval time

AlarmManager am[] = new AlarmManager[6] ;
PendingIntent mAlarmSender[] = new PendingIntent[6] ;

cnt = 6 /* Mon to Sun* or if Mon or any single day only/
mDays[i]  = can be from Mon to Sun or just Mon(one day only)

for (int i= 0; i < cnt ; i++)
{
     am[i] = (AlarmManager)getSystemService(ALARM_SERVICE);
     firstTime = setAlarmTime(mDays[i], mHour, mMinute,
sAmPm) ;
     am[i].setRepeating(AlarmManager.RTC_WAKEUP, firstTime, intrvl,
mAlarmSender[i]);
}

private static long setAlarmTime(String mDay, int mHour, int mMinute,
String sAmPm) {
        /* Compare the current calendar time with the time set by user */
        String calAmPm ;
        int mDayNumber = 0 ;
        int hrDiff = 0 ;
        int minDiff = 0 ;

        mDayNumber = convertToDayNumber(mDay) ;

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        int mDy  = calendar.get(Calendar.DAY_OF_WEEK);
        int mHr  = calendar.get(Calendar.HOUR);
        int mMin = calendar.get(Calendar.MINUTE);
        int mAP = calendar.get(Calendar.AM_PM);

        if ( mAP == 0 )
                calAmPm = "AM" ;
        else
                calAmPm = "PM" ;

        if (sAmPm.compareTo(calAmPm) == 0)
        {
            if (mHour > mHr)
                /*user entered alarm time is 9:00PM vs  phone time of
5:00PM */
                hrDiff = mHour - mHr ;     //4
            else if (mHour < mHr)
                /* 9:00PM 11:00PM*/
                hrDiff = 24 - (mHr - mHour) ;
            else
                hrDiff = 0 ;

                if (mMinute > mMin)
                        /* 9:30PM vs 5:15PM */
                minDiff = mMinute - mMin ;         //15
            else if (mMinute < mMin)
                /* 9:10PM 11:15PM */
                minDiff = 60 - (mMin - mMinute) ; //55
            else
                minDiff = 0 ;
        }
        else if (sAmPm.compareTo("PM") == 0 && calAmPm.compareTo("AM")
== 0 ) {
                /* 9:00PM vs 5:00AM  9:00PM 11:00AM*/
                if (mHour > mHr)
                hrDiff = 12 + (mHour - mHr) ;     //16
            else if (mHour < mHr)
                hrDiff = 12 - (mHr - mHour) ; //10
            else
                hrDiff = 0 ;

                /* 9:30PM vs 5:15PM  9:10PM 11:15PM*/
                if (mMinute > mMin)
                minDiff = mMinute - mMin ;         //15
            else if (mMinute < mMin)
                minDiff = 60 - (mMin - mMinute) ; //55
            else
                minDiff = 0 ;
        }
        else if (sAmPm.compareTo("AM") == 0 && calAmPm.compareTo("PM")
== 0 ) {
                /* 9:00AM vs 5:00PM  9:00AM 11:00PM*/
                if (mHour > mHr)
                        hrDiff = 12 + (mHour - mHr) ;     //16
                else if (mHour < mHr)
                        hrDiff = 12 - (mHr - mHour) ; //10
                else
                        hrDiff = 0 ;

                /* 9:30PM vs 5:15PM  9:10PM 11:15PM*/
                if (mMinute > mMin)
                        minDiff = mMinute - mMin ;         //15
                else if (mMinute < mMin)
                        minDiff = 60 - (mMin - mMinute) ; //55
                else
                        minDiff = 0 ;
        }
        /* this add means were adding the hour and min diff of the user
entered time with the current time */
        if (hrDiff == 1 && minDiff > 0)
                calendar.add(Calendar.HOUR,0);
        else
                calendar.add(Calendar.HOUR,hrDiff);

        calendar.add(Calendar.MINUTE,minDiff);
        calendar.add(Calendar.DAY_OF_WEEK,getDayDiff(mDayNumber, mDy));

        /* since we have added new values for day, hours and min needed
to our current calendar time, get             its            long
value */
        return calendar.getTimeInMillis() ;
  }

--~--~---------~--~----~------------~-------~--~----~

2. ADC2 submission: Aurora Device Search (was Aurora 1.0 is available in MarketPlace - more than device search)

Hi community,

I'm happy to announce that  Aurora Device Search has been submitted to ADC2.
It has been published in MarketPlace for a while, and already get many good
feedback from the community (
http://www.cyrket.com/package/com.aurora.android.search). Thanks a lot to
the community!  Here's a short introduction of Aurora Device Search.

Aurora Device search is a full text device search tool on Android. Like
spotli...@mac, Aurora shows search result dynamically as typing. Searched
data scope include:

* Contacts
* Calendar Event
* Application name
* Web history
* Web bookmark
* SMS/MMS
* Audio
* Video
* Image
* SDCard files

What's more, Aurora emphasizes the intelligence of search ranking, and user
accessibility. Highlight features include not limited to:

* Intelligent search ranking based on user behavior. Most frequently used
resources will in the top list. Aurora learns user's habit so that the
longer time you use Aurora, the less letters you may type to find the target
resource.

* Quick share data to your friends. User can share contact card, calendar
event, web link, pictures, and all kinds of data to friends via
sms/mms/gmail.

* Shortcut buttons. It makes user operation much easier. i.e uninstalling an
application, user only needs to type first letters of the application name,
and press "manage" button in the screen. Much easier than going to "Setting"
-> "Manage application" -> .... -> "Uninstall".

* Convenient context menu. Most operations can be done via context menu, so
that Aurora can be your mobile entry.

and more...

Experience Aurora by downloading from MarketPlace!
Any comment, suggestion and bug report are highly appreciated. Please
mailto:3crownt...@gmail.com. Thank you!





--~--~---------~--~----~------------~-------~--~----~

3. Key & Value pair in a spinner

4. AlarmClock app API ?

5. submenu

6. Still seriously perplexed about how to build the dev environment

7. MapView Not zooming to center but to top left