私はgithubのslidemenuの例を使用しています。スライドメニューはテキストとヘッダーのみで表示されていますが、別のアイコンを追加する必要があります。カスタムアダプターを使用しようとしていますが、機能していません...
スライドメニュー.java:
public class SlideMenu implements SlideMenuAnimationContainer.Listener {
public final static String[] slideMenuOptions = { "Recent Update", "Notification", "Wardrobe" };
public final static String TAG = "SlideMenu";
protected static final String TextView = null;
Intent intent;
private Context context;
private SlideMenuAnimationContainer slideMenuAnimationContainer;
public SlideMenu( Context context, SlideMenuAnimationContainer mainAnimationLayout){
this.context = context;
this.slideMenuAnimationContainer = mainAnimationLayout;
}
public void init(){
final Activity activity = (Activity) context;
//Set Content's show menu button's action
ImageView showMenuButton = (ImageView) activity.findViewById( R.id.content_button);
showMenuButton.setOnClickListener( new OnClickListener(){
@Override
public void onClick( View v){
slideMenuAnimationContainer.toggleSlideMenu();
}
});
//Contruct the SlideMenu items here, you can replace this ArrayAdapter with your customr ArrayAdapter
List<SlideMenuItem> slideMenuList = new ArrayList<SlideMenuItem>();
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Updates"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Recent Update"));
// slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Header 2"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Notification"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Category"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Wardrobe"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Gadgets"));
SlideMenuArrayAdapter slideMenuArrayAdaptar = new SlideMenuArrayAdapter( context, android.R.layout.simple_list_item_1, slideMenuList);
ListView menuListView = (ListView) activity.findViewById( R.id.slideMenuListView);
menuListView.setAdapter( slideMenuArrayAdaptar);
menuListView.setOnItemClickListener( new OnItemClickListener(){
@Override
public void onItemClick( AdapterView<?> parent, View view, int position, long id){
// Close sidebar
slideMenuAnimationContainer.closeSlideMenuAndActOnClick( parent, view, position, id);
}
});
//Implement your logic here within the execute() function when an item is clicked with in the SlideMenu
//Called after the SlideMenu collapses.
slideMenuAnimationContainer.setMenuItemSelectedAction( new MenuItemSelectedAction(){
@Override
public void execute( AdapterView<?> parent, View view, int position, long id){
//Only act when a ListViewItem with type Activity is clicked
TextView textView = (TextView)view.findViewById( R.id.MenuActivityListViewItem_text);
if( textView != null && textView.getId() == R.id.MenuActivityListViewItem_text){
//Start new activity
CharSequence selectedActivityName = textView.getText();
if( selectedActivityName.equals( "Recent Update")) {
intent = new Intent( activity, Activity1.class);
}
else if( selectedActivityName.equals( "Notification")) {
intent = new Intent( activity, Activity2.class);
}
else if( selectedActivityName.equals( "Wardrobe")) {
intent = new Intent( activity, Activity3.class);
}
else if( selectedActivityName.equals( "Gadgets")) {
intent = new Intent( activity, Gadgets_Activity.class);
}
intent =intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.startActivity( intent);
}
}
});
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
@Override
public void onSlideMenuOpened(){
Log.d( TAG, "opened");
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
@Override
public void onSlideMenuClosed(){
Log.d( TAG, "closed");
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
@Override
public boolean onContentTouchedWhenOpening(){
//The content area is touched when sidebar opening, close sidebar
Log.d( TAG, "going to close sidebar");
slideMenuAnimationContainer.closeSlideMenu();
return true;
}
}
およびアダプター:
public class SlideMenuArrayAdapter extends ArrayAdapter<SlideMenuItem> {
private List<SlideMenuItem> slideMenuItemList;
public SlideMenuArrayAdapter( Context context, int textViewResourceId, List<SlideMenuItem> slideMenuItemList) {
super( context, textViewResourceId, slideMenuItemList);
this.slideMenuItemList = slideMenuItemList;
}
@Override
public View getView( int position, View view, ViewGroup parent) {
SlideMenuItem slideMenuItem = slideMenuItemList.get( position);
LayoutInflater layoutInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Header){
view = layoutInflater.inflate( R.layout.menu_header_listview_item, null);
TextView textView = (TextView) view.findViewById( R.id.MenuListHeaderListViewItem_text);
textView.setText( slideMenuItem.getText());
}
else if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Activity){
view = layoutInflater.inflate( R.layout.menu_activity_listview_item, null);
TextView textView = (TextView) view.findViewById( R.id.MenuActivityListViewItem_text);
textView.setText( slideMenuItem.getText());
}
else{
view = null; //Left for operation
}
return view;
}
}