Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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 Listview添加所有组件时出现问题_Android - Fatal编程技术网

Android Listview添加所有组件时出现问题

Android Listview添加所有组件时出现问题,android,Android,我是androidStudio的新手。我使用relativeLayout创建了一个包含ListView、textview和EditText的xml文件。当我把编辑文本放在文本视图旁边时,ListView“抓取”了这个组件,我不能再点击列表项了。我只想有一个编辑文本,可以点击我的列表 我尝试过改变布局,但没有任何效果 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://sche

我是androidStudio的新手。我使用relativeLayout创建了一个包含ListView、textview和EditText的xml文件。当我把编辑文本放在文本视图旁边时,ListView“抓取”了这个组件,我不能再点击列表项了。我只想有一个编辑文本,可以点击我的列表

我尝试过改变布局,但没有任何效果

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context=".CNE">

<ListView
    android:id="@+id/listaCNE"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<TextView
    android:id="@+id/textCand"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/listaCNE"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/txtA"
    android:text="Candidatos" />

<EditText
    android:id="@+id/txtA"
    android:layout_width="96dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/listaCNE"
    android:layout_alignParentRight="true" />
</RelativeLayout>

我不知道你想要实现什么UI,但我只是假设这里有一个UI,然后这里是.xml。ListView项目也可以单击,正如你在图片上看到的,它显示了我单击的位置的祝酒词

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/ll"
        android:padding="16dp">

    </ListView>

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <EditText
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:hint="EditText"
            android:gravity="center"/>

        <TextView
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="TextView"
            android:gravity="center"/>

    </LinearLayout>

</RelativeLayout>

我不知道你想要实现什么UI,但我只是假设这里有一个UI,然后这里是.xml。ListView项目也可以单击,正如你在图片上看到的,它显示了我单击的位置的祝酒词

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/ll"
        android:padding="16dp">

    </ListView>

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <EditText
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:hint="EditText"
            android:gravity="center"/>

        <TextView
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="TextView"
            android:gravity="center"/>

    </LinearLayout>

</RelativeLayout>

所以我解决了我的问题,我有两个单独的xml文件,一个是“activity\u cne.xml”,这实际上就是我想要的UI。另一个是“listob.xml”,它定义了显示ListView的元素这里是文件(我在activity_cne.xml文件中添加了一些组件):


对于listob.xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtitem"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

这是我的adpater以防万一(nombres是填充ListView的字符串数组列表:

 setContentView(R.layout.activity_cne);
    lista=(ListView)findViewById(R.id.listaCNE);

    arrayAdapter= new ArrayAdapter<String>(this, R.layout.listob, R.id.txtitem,nombres);
setContentView(R.layout.activity_cne);
lista=(ListView)findViewById(R.id.ListView);
arrayAdapter=新的arrayAdapter(this,R.layout.listob,R.id.txtitem,nombres);

所以我解决了我的问题,我有两个单独的xml文件,一个是“activity\u cne.xml”,它实际上就是我想要的UI。另一个是“listob.xml”,它定义了显示ListView的元素这里是文件(我在activity\u cne.xml文件中添加了一些组件):


对于listob.xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtitem"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

这是我的adpater以防万一(nombres是填充ListView的字符串数组列表:

 setContentView(R.layout.activity_cne);
    lista=(ListView)findViewById(R.id.listaCNE);

    arrayAdapter= new ArrayAdapter<String>(this, R.layout.listob, R.id.txtitem,nombres);
setContentView(R.layout.activity_cne);
lista=(ListView)findViewById(R.id.ListView);
arrayAdapter=新的arrayAdapter(this,R.layout.listob,R.id.txtitem,nombres);

0dp相对宽度?是的,我在android开发者网站上遵循指南。我把它改回10dp,但我仍然有同样的问题。你能扩展什么“抓取”吗意思是?不清楚你想要实现什么以及实际的问题是什么。这就像在列表的每个元素上创建了一个EditText,所以我不能单击列表本身,但我只能单击创建的不需要的EditText。我只想要一个列表、一个文本和一个编辑文本;但我不知道为什么要将EditText放在xml上它在RelativeLayout中将多个EditText创建到list0dp宽度中?是的,我在android开发者网站上遵循指南。我将其改回10dp,但我仍然有相同的问题。你能扩展什么“抓取”吗意思是?不清楚你想要实现什么以及实际的问题是什么。这就像在列表的每个元素上创建了一个EditText,所以我不能单击列表本身,但我只能单击创建的不需要的EditText。我只想要一个列表、一个文本和一个编辑文本;但我不知道为什么要将EditText放在xml上它会在列表中创建多个EditText是的,这正是我想要实现的UI。我一直都知道我的问题所在。我在用xml定义ListView的元素。因此,当我添加EditText时,我实际上并没有在ListView之后放一个EditText,而是为ListView的每个元素放一个编辑文本。Ty用于解释我很高兴我的解决方案能帮上忙是的,这正是我想要实现的UI。我一直都知道我的问题所在。我在用xml定义ListView的元素。所以当我添加EditText时,我并没有在ListView之后放一个EditText,而是为每个元素放一个编辑文本对于ListView.Ty,我非常感谢您解释我想要的UI。稍后我会发布我的解决方案,我很高兴它能帮上忙