Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我点击抽屉关闭的任何地方时,Android在导航抽屉中_Android_Navigation Drawer - Fatal编程技术网

当我点击抽屉关闭的任何地方时,Android在导航抽屉中

当我点击抽屉关闭的任何地方时,Android在导航抽屉中,android,navigation-drawer,Android,Navigation Drawer,在导航抽屉中,当我按下按钮或其他任何东西时,抽屉就会关闭。有什么问题? 我在网上搜索,但没有找到任何与我的代码不同的东西。也许有一些错误,但我没有发现 代码: index.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" andro

在导航抽屉中,当我按下按钮或其他任何东西时,抽屉就会关闭。有什么问题? 我在网上搜索,但没有找到任何与我的代码不同的东西。也许有一些错误,但我没有发现

代码:

index.xml

<?xml version="1.0" encoding="utf-8"?>
<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:background="#bbb9b9b9">



    <ListView
        android:id="@+id/listViewDrawer"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:background="#fff"
        android:padding="3dp"
        android:choiceMode="singleChoice"
        android:dividerHeight="1dp"
        android:divider="@android:color/transparent">
    </ListView>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="10">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:weightSum="10">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnMalt"
            android:layout_weight="1.5"
            android:src="@drawable/mal" />


        <EditText
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/legerin_ett"
            android:layout_weight="5.5"
            android:hint="@string/legerin_text" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnLegerint"
            android:layout_weight="1.5"
            android:src="@drawable/legerin" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnDerkevet"
            android:layout_weight="1.5"
            android:src="@drawable/derkeve" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sernavt"
        android:gravity="center"
        android:text="sepana tirşikê ji bo telefonên jîr"
        android:textStyle="bold"
        android:textColor="#ff000000"
        android:textSize="20dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="3dp" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/listViewt"
        android:layout_gravity="center_horizontal"
        android:layout_weight="9"
        android:layout_marginBottom="5dp" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:text="@string/peyameke_binivise"
        android:id="@+id/buttonPeyamBinivise"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" />

    </LinearLayout >
</android.support.v4.widget.DrawerLayout>

在main.java相关代码中:

NuceMijarAdapter adapter1 = new NuceMijarAdapter(Index.this,R.layout.list_mijar_layout,arr);
lvDrawer.setAdapter(adapter1);


private class NuceMijarAdapter extends ArrayAdapter<String> {
    private ArrayList<String> items;

    public NuceMijarAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.list_mijar_layout, null);
        }
        final String o = items.get(position);
        if (o != null) {
            String htmlText = o.replace("<a href=\"index.php?","<a href=\"http://www.tirsik.net/index.php?")
                    .replace("padding-left:8px","padding-left:1px")
                    .replace(" » ","");
            final NuceMijarIro nuce = mijarIroAction(htmlText);
            Button tvMijar = (Button) v.findViewById(R.id.tvMijar);
            Button tvHejmar = (Button) v.findViewById(R.id.tvHejmar);
            tvMijar.setText(nuce.mijar);
            tvHejmar.setText(nuce.hejmar);

            tvMijar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.d("url: ", nuce.link);
                    if(nuce.link.contains("index.php?mijar")) {
                        urlIndex = nuce.link;
                        if(teketin) mijarRasthatiTeketi("bnr");
                        else mijarRasthati("bnr");
                    }
                }
            });
        }
        return v;
    }
}
NuceMijarAdapter adapter1=新的NuceMijarAdapter(Index.this,R.layout.list\u mijar\u layout,arr);
lvDrawer.setAdapter(适配器1);
私有类NuceMijarAdapter扩展了ArrayAdapter{
私有ArrayList项;
public numecmijaradapter(上下文上下文、int textViewResourceId、ArrayList项){
super(上下文、textViewResourceId、项);
这个项目=项目;
}
@TargetApi(构建版本代码蜂窝)
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
v=vi.充气(R.layout.list\u mijar\u layout,空);
}
最终字符串o=items.get(位置);
如果(o!=null){

字符串htmlText=o.replace(“我曾经遇到过同样的问题

我有一个RecyclerView NavigationDrawer,只需将导航代码移到xml文件的底部,我的问题就解决了

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

//some code here for the body of your activity

</RelativeLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="350dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="#ffffff"
    android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>

//这里有一些活动主体的代码
希望它对你也有用…

更多解释

<ListView
        android:id="@+id/listViewDrawer"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:background="#fff"
        android:padding="3dp"
        android:choiceMode="singleChoice"
        android:dividerHeight="1dp"
        android:divider="@android:color/transparent">
    </ListView>

将成为您的内容,而其他内容实际上将成为您的
导航抽屉

请查看它的工作原理:

上面写着:

以下布局使用带有两个子视图的
抽屉布局
:a
FrameLayout
以包含主要内容(由位于 运行时)和导航抽屉的列表视图


使用新的
SupportLibrary

提供的
NavigationDrawer
,我强烈建议您使用新的设计库,因为您才刚刚开始:。您的问题是什么?您不想发生的事情是什么,或者您试图创建的行为是什么?请详细说明一下更多。有一个按钮列表,当我单击它们时,应用程序将解析一个url并列出一个文本列表。但是当我单击抽屉时,应用程序将关闭,而应用程序不执行任何操作。在此处检查我的答案:这意味着导航视图应该放在前面。
NavigationView.bringToFront()
等同于此答案