This reply is a little late, but hopefully it will still help you or others
out there with the same question.
Since you are talking about inflating the layout from XML I am assuming you
already have a custom Preference class that you have created. After
inflating you need to call findActivity to get the exact preference you want
to add the click listener to... You will want to implement
OnPreferenceClickListener and then call
Preference.setOnPreferenceClickListener() on that preference.
I found that I do this quite often, so what I did is create a class that
implements OnPreferenceClickListener. It is really quite simple so I'll
just show the code for the class below. The constructor of my class takes a
context and a class object. The class object is the activity you want to
launch. Since this class does not inherit from Context it is important to
not store the context that is passed in but rather to get the Application's
context and store that... That is what will be used to call startActivity.
public class PrefScreenLaunchListener implements OnPreferenceClickListener
{
Class<?> m_class;
Context m_context;
public PrefScreenLaunchListener(Context context, Class<?> classObj)
{
m_class = classObj;
m_context = context.getApplicationContext();
}
@Override
public boolean onPreferenceClick(Preference preference)
{
Intent launchIntent = new Intent(m_context, m_class);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
m_context.startActivity(launchIntent);
return true;
}
}
Hope that helps,
Justin
----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------
On Mon, May 3, 2010 at 7:16 AM, Mohammad Siddiqui
<[email protected]>wrote:
> Hi everyone,
>
> I want to lunch a actvitity when click on a prefrence(inflated form
> the xml ).
> how we can do it
>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> [email protected]<android-beginners%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en