隐藏列表视图标题的一部分文本

问题描述

我有一个Adapter和一个标头的listView。我想选择隐藏listview的哪些列;它适用于textViewIdBaseDatos.setVisibility(View.GONE)在我的适配器中的列表视图,但是我不能在标题中这样做。我可以在header.xml中用android:visibility="gone"中的textView进行隐藏,但是我想选择要显示/隐藏哪些列作为首选项。

您可以在屏幕上看到标题和listView

capture of the screen


header.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:background="@color/fondoAccent">

    <TextView
        android:id="@+id/editTextIdBaseDatos"
       
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:maxLength="2"
        android:text="@string/idbasedatos"
        android:textColor="@color/headlineList"
        android:textSize="@dimen/testSizeHeadList"
        android:background="@color/fondoAccent2"/>

    <TextView
        android:id="@+id/editTextPriority"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:maxLength="1"
        android:text="@string/priority"
        android:textColor="@color/headlineList"
        android:textSize="@dimen/testSizeHeadList"

        android:background="@color/fondoAccent2"/>

    <TextView
        android:id="@+id/editTextTarea"
        android:layout_width="115dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:maxLength="7"
        android:text="@string/task"
        android:textSize="@dimen/testSizeHeadList"
        android:textColor="@color/headlineList"
        android:background="@color/fondoAccent2"/>

片段的一部分,显示标题和listView

    Adapter = new MyAdapter(getActivity(),R.id.listView,idBaseDatos,name,description,start,startime,finished,duration,priority); // enlazamos el adaptador que hemos creado en clase java myAdapter con nuestra vista
        listView.setAdapter(myAdapter);
        listView.addHeaderView(headerView); // añade la cabecera a la listView

myAdapter的一部分:

public class MyAdapter extends BaseAdapter {
    // 3 variables
    private Context context;
    private int layout;
    private List<String> priority;
    private List<String> nameTask;
    private List<String> description;
    private List<String> start;
    private List<String> startime;
    private List<String> idBasedatos;
    private List<Integer> finished;
    private List<String> duration;
    // private int colorFinished = 0xFF00FF00 ;
    private  int colorFinished;


    // constructor que recoge el contexto,el layout y los nombres
    public MyAdapter(Context context,int layout,List<String> idBasedatos,List<String> nameTask,List<String> description,List<String> start,List<String> startime,List<Integer> finished,List<String> duration,List<String> priority){
        this.context = context;
        this.priority = priority;
        this.layout = layout;
        this.nameTask = nameTask;
        this.description = description;
        this.start = start; // date
        this.startime = startime; // time in 24 H format
        this.duration = duration;
        this.idBasedatos = idBasedatos;
        this.finished = finished; // Integer que hay que pasar a booleano
        colorFinished = ContextCompat.getColor(context,R.color.colorPrimarySoft);

解决方法

您必须首先使用listView作为其父级为标题视图充气。 现在,您可以在此标题视图上执行任何操作,然后再将其作为标题添加到listView。例如:

ListView listView = findViewById(R.id.list);
View header = getLayoutInflater().inflate(R.layout.header,listView,false);
header.findViewById(R.id.viewToHide).setVisibility(View.GONE);
listView.addHeaderView(header);

您还可以参考其他类似的答案:https://stackoverflow.com/a/25867095/2621237

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...