Reputation: 769
I defined a layout view in a .xml file called profile_sliding_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#b5b5b5" />
<TextView
android:id="@+id/pMenuProfileInformation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_profile_information"
android:drawablePadding="5dp"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingTop="3dp"
android:clickable="true"
android:text="@string/pMenuProfileInformation"
android:textAppearance="?android:attr/textAppearanceMedium" />
..........
</LinearLayout>
I'm creating the SlidingMenu from code:
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.profile_sliding_menu);
It shows perfectly the menu, but i want to do some actions when the user chooses an option from the menu. How can i access that buttons and assign them a event?
Thanks!
Upvotes: 1
Views: 2545
Reputation: 1828
The jfeinstein slidingmenu example uses SampleListFragment Adapter that extends ListFragment
ListFragment has an overriding method "onListItemClick()" that can be used for implementing slidemenu item click actions based on the menu position
@Override
public void onListItemClick(ListView l, View v, int position, long id){
Toast.makeText(getActivity().getApplicationContext(),"Clicked", Toast.LENGTH_SHORT).show();
}
Upvotes: 0
Reputation: 769
I make something like this, and all work fine:
findViewById(R.id.pMenuProfileInformation).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"blablabal", Toast.LENGTH_SHORT).show();
}
});
Upvotes: 3