android-具有SlidingNavigationDrawer的OnItemClickListener

android-具有SlidingNavigationDrawer的OnItemClickListener,第1张

概述我有一个android项目和一个滑动导航抽屉.我已经建立了一个管理库,该库允许您将多种不同类型的控件添加到导航菜单.我有一个问题,尽管没有调用OnItemClickListener.我发现“setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS)”;从https://code.google.com/p/android/issues/deta

我有一个android项目和一个滑动导航抽屉.我已经建立了一个管理库,该库允许您将多种不同类型的控件添加到导航菜单.

我有一个问题,尽管没有调用OnItemClickListener.我发现“ setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS)”;从https://code.google.com/p/android/issues/detail?id=3414#c27开始,但这没有帮助.

以下是我的代码的创建方式:

    private DrawerLayout mDrawerLayout;    private ListVIEw mDrawerList;    private ActionbarDrawerToggle mDrawerToggle;    public static Activity activity;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        FragmentTransaction t = getSupportFragmentManager().beginTransaction();        Fragment frag = new MainFragment();        t.replace(R.ID.content_frame, frag);        //t.commit();        init();         NavigationManager navManager = new NavigationManager(this, mDrawerLayout,                 R.string.drawer_open, R.string.drawer_closed);         navManager.prepareActionbar();         NavigationManagerAdapter menuAdapter = new NavigationManagerAdapter(this);        menuAdapter.add(new NavigationMenuItem("Products", "MENU_PRODUCTS",                NavigationMenuItem.GuiType.TEXTVIEW, null));        mDrawerList.setAdapter(menuAdapter);        mDrawerList.setonItemClickListener(this);

}

private voID init() {    // Todo auto-generated method stub    mDrawerLayout = (DrawerLayout) findVIEwByID(R.ID.drawer_layout);    mDrawerList = (ListVIEw) findVIEwByID(R.ID.left_drawer);}

我的FragmentActivity实现了ListItem.OnItemClickListener.

下面是我的XML代码

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:clickable="false"    androID:descendantFocusability="blocksDescendants"    androID:focusable="false"    androID:focusableIntouchMode="false">    <androID.support.v4.Widget.DrawerLayout        xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:ID="@+ID/drawer_layout"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:descendantFocusability="blocksDescendants">        <FrameLayout            androID:ID="@+ID/content_frame"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent" />        <ListVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:ID="@+ID/left_drawer"            androID:layout_wIDth="280dp"            androID:layout_height="match_parent"            androID:layout_gravity="start"            androID:paddingleft="@dimen/List_padding"            androID:paddingRight="@dimen/List_padding"            androID:choiceMode="singleChoice"            androID:divIDer="#4e4e4e"            androID:divIDerHeight="1dp"            androID:background="#111"            androID:clickable="false"androID:descendantFocusability="blocksDescendants" /></androID.support.v4.Widget.DrawerLayout></relativeLayout>

感谢您的任何帮助,您可以提供

更新1

我已经查明了问题所在,这与我的图书馆有关.

如果我在以下代码中添加到适配器,则它将起作用:

mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_List_item, mPlanetTitles));

如果我使用自定义适配器手动创建适配器并进行设置,则onitemclickListener会停止工作.

以下是我添加到适配器并将适配器设置为列表视图的方式

NavigationManagerAdapter menuAdapter = new NavigationManagerAdapter(MainActivity.this);        menuAdapter.add(new NavigationMenuItem("MenuItem", "MENU_PRODUCTS", GuiType.TEXTVIEW, null));        mDrawerList.setAdapter(menuAdapter);

以下是我的NavigationManagerAdapter的代码

public class NavigationManagerAdapter extends ArrayAdapter<NavigationMenuItem>{    public NavigationManagerAdapter(Context context)    {        super(context, 0);    }    public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent)    {        try        {            convertVIEw = LayoutInflater.from(getContext()).inflate(R.layout.row_menu_item, null);            if (getItem(position).iconRes != -1)            {                ImageVIEw icon = (ImageVIEw)convertVIEw.findVIEwByID(R.ID.row_icon);                icon.setVisibility(VIEw.VISIBLE);                icon.setimageResource(getItem(position).iconRes);                if (getItem(position).onClickListener != null)                {                    icon.setonClickListener(getItem(position).onClickListener);                }            }            switch (getItem(position).guiType)            {                case TEXTVIEW:                    TextVIEw standardTextVIEw = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_textvIEw);                    standardTextVIEw.setText(getItem(position).menuname);                    standardTextVIEw.setVisibility(VIEw.VISIBLE);                    if (getItem(position).onClickListener != null)                    {                        standardTextVIEw.setonClickListener(getItem(position).onClickListener);                    }                    if (getItem(position).tag != null)                    {                        standardTextVIEw.setTag(getItem(position).tag);                    }                    break;                case header:                    TextVIEw textVIEwheader = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_header);                    textVIEwheader.setText(getItem(position).menuname);                    textVIEwheader.setVisibility(VIEw.VISIBLE);                    break;                case SUBheader:                    TextVIEw textVIEwSubheader = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_subheader);                    textVIEwSubheader.setText(getItem(position).menuname);                    textVIEwSubheader.setVisibility(VIEw.VISIBLE);                    break;                case SUB_TEXTVIEW:                    TextVIEw textVIEwSubItem = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_subTextVIEw);                    textVIEwSubItem.setText(getItem(position).menuname);                    textVIEwSubItem.setVisibility(VIEw.VISIBLE);                    textVIEwSubItem.setonClickListener(getItem(position).onClickListener);                    textVIEwSubItem.setTag(getItem(position).tag);                    break;                case SWITCH:                    if (androID.os.Build.VERSION.SDK_INT >= androID.os.Build.VERSION_CODES.HONEYCOMB)                    {                        Switch switchbutton = (Switch)convertVIEw.findVIEwByID(R.ID.row_switch);                        switchbutton.setText(getItem(position).menuname);                        if (getItem(position).tag != null)                        {                            switchbutton.setTag(getItem(position).tag);                        }                        switchbutton.setVisibility(VIEw.VISIBLE);                        switchbutton.setonCheckedchangelistener(getItem(position).onCheckedchangelistener);                        switchbutton.setChecked(getItem(position).defaultValue);                    }                    else                    {                        throw new ComponentNotSupportedOnAPIException("Switches are not supported in API Version: " + androID.os.Build.VERSION.SDK_INT);                    }                    break;                case TEXTVIEW_SUMMARY:                    TextVIEw spannedTextVIEw = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_textvIEw);                    String menuTitle = getItem(position).menuname;                    String summary = getItem(position).summary;                    spannedTextVIEw.setText(HTML.fromHTML(menuTitle + "<br /><small><Font color='#9f9f9f'>" + summary + "</Font></small>"));                    spannedTextVIEw.setVisibility(VIEw.VISIBLE);                    if (getItem(position).onClickListener != null)                    {                        spannedTextVIEw.setonClickListener(getItem(position).onClickListener);                    }                    if (getItem(position).tag != null)                    {                        spannedTextVIEw.setTag(getItem(position).tag);                    }                    break;                case header_SUMMARY:                    TextVIEw spannedheader = (TextVIEw)convertVIEw.findVIEwByID(R.ID.row_header);                    String headerTitle = getItem(position).menuname;                    String headerSummary= getItem(position).summary;                    spannedheader.setText(HTML.fromHTML(headerTitle + "<br /><small><Font color='#000000'>" + headerSummary + "</Font></small>"));                    spannedheader.setVisibility(VIEw.VISIBLE);                    break;                case button:                    button button = null;                    if (getItem(position).isborderless)                    {                        button = (button)convertVIEw.findVIEwByID(R.ID.row_button_borderless);                    }                    else                    {                        button = (button)convertVIEw.findVIEwByID(R.ID.row_button);                    }                    button.setText(getItem(position).menuname);                    button.setonClickListener(getItem(position).onClickListener);                    button.setVisibility(VIEw.VISIBLE);                    break;            }        }        catch (ComponentNotSupportedOnAPIException ex)        {            Log.e("Adapter Error", ex.toString());        }        return convertVIEw;    }

感谢您的任何帮助,您可以提供

解决方法:

我已经设法解决了这个问题.

我必须运行以下命令,以便将项目单击传递到列表视图.

standardTextVIEw.setFocusable(false);standardTextVIEw.setFocusableIntouchMode(false);standardTextVIEw.setClickable(false);

谢谢你的帮助.

总结

以上是内存溢出为你收集整理的android-具有SlidingNavigationDrawer的OnItemClickListener全部内容,希望文章能够帮你解决android-具有SlidingNavigationDrawer的OnItemClickListener所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1076960.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存