Android 文本字段不为';不出现在应用程序中

Android 文本字段不为';不出现在应用程序中,android,textview,android-recyclerview,Android,Textview,Android Recyclerview,我正在从我的SQLite数据库中检索信息,并通过ArrayList将其显示在RecyclerView中。我的代码工作正常,没有错误,但是,我试图显示的4个textview中有1个无法显示,即使它采用与其他3个完全相同的方法,我也不知道为什么 使用RecyclerView的活动: public void search(View view) { // || is the concatenation operation in SQLite cursor = db.rawQuery("

我正在从我的
SQLite
数据库中检索信息,并通过
ArrayList
将其显示在
RecyclerView
中。我的代码工作正常,没有错误,但是,我试图显示的4个
textview
中有1个无法显示,即使它采用与其他3个完全相同的方法,我也不知道为什么

使用RecyclerView的活动:

public void search(View view) {
    // || is the concatenation operation in SQLite

    cursor = db.rawQuery("SELECT _id, Name, Surname, Department, Workplace FROM LysandrosTable WHERE Name || ' ' || Surname LIKE ?",
            new String[]{"%" + searchText.getText().toString() + "%"});

    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);

    lysandrosHelper = new LysandrosDatabaseAdapter(this);
    mRecyclerView.setAdapter(new EmployeeListAdapter(lysandrosHelper.getAllDat(), R.layout.custom_row2));

}
适配器类:

public class ViewHolder extends RecyclerView.ViewHolder {

    public TextView txtFirstName_Recycler;
    public TextView txtLastName_Recycler;
    public TextView txtDepartment_Recycler;
    public TextView txtWorkplace_Recycler;

    public ViewHolder(View itemView) {

        super(itemView);

        txtFirstName_Recycler = (TextView) itemView.findViewById(R.id.first_name_recycler);
        txtLastName_Recycler = (TextView) itemView.findViewById(R.id.last_name_recycler);
        txtDepartment_Recycler = (TextView) itemView.findViewById(R.id.department_recycler);
        txtWorkplace_Recycler = (TextView) itemView.findViewById(R.id.workplace_recycler);
    }

}

public void onBindViewHolder(ViewHolder holder, int position) {

    DataBean item = items.get(position);

    holder.txtFirstName_Recycler.setText(item.getName());
    holder.txtLastName_Recycler.setText(item.getSurname());
    holder.txtDepartment_Recycler.setText(item.getDepartment());
    holder.txtWorkplace_Recycler.setText(item.getWorkplace());

}
我的数据库类和相应的方法:

public List <DataBean> getAllDat(){

    List<DataBean> list = new ArrayList<>();

    SQLiteDatabase db = helper.getReadableDatabase();

    String [] columns = {LysandrosHelper.UID, LysandrosHelper.NAME, LysandrosHelper.SURNAME, LysandrosHelper.DEPARTMENT, LysandrosHelper.WORKPLACE};
    Cursor cursor = db.query(LysandrosHelper.TABLE_NAME, columns, null, null, null, null, null);

    while (cursor.moveToNext()) {

        int index = cursor.getColumnIndex(LysandrosHelper.UID);
        int index2 = cursor.getColumnIndex(LysandrosHelper.NAME);
        int index3 = cursor.getColumnIndex(LysandrosHelper.SURNAME);
        int index4 = cursor.getColumnIndex(LysandrosHelper.DEPARTMENT);
        int index5 = cursor.getColumnIndex(LysandrosHelper.WORKPLACE);
        int cid = cursor.getInt(index);

        String persoName = cursor.getString(index2);
        String personSurname = cursor.getString(index3);
        String personDepartment = cursor.getString(index4);
        String personWorkplace = cursor.getString(index5);

        DataBean bean = new DataBean(cid, persoName, personSurname, personDepartment, personWorkplace);
        list.add(bean);
    }

    return list;
}
public List getAllDat(){
列表=新的ArrayList();
SQLiteDatabase db=helper.getReadableDatabase();
String[]列={lysandshelper.UID,lysandshelper.NAME,lysandshelper.姓氏,lysandshelper.DEPARTMENT,lysandshelper.WORKPLACE};
Cursor Cursor=db.query(lysandshelper.TABLE_名称、列、null、null、null、null);
while(cursor.moveToNext()){
int index=cursor.getColumnIndex(lysandshelper.UID);
int index2=cursor.getColumnIndex(lysandshelper.NAME);
int index3=cursor.getColumnIndex(lysandshelper.姓氏);
int index4=cursor.getColumnIndex(lysandshelper.DEPARTMENT);
int index5=cursor.getColumnIndex(lysandshelper.WORKPLACE);
int-cid=cursor.getInt(索引);
String persoName=cursor.getString(index2);
String personSurname=cursor.getString(index3);
String personDepartment=cursor.getString(index4);
String personWorkplace=cursor.getString(index5);
DataBean=新数据库(cid、persoName、personSurname、personDepartment、personWorkplace);
添加(bean);
}
退货清单;
}
以及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:padding="16dp"
>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cv"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/icon"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="16dp"
            android:src="@drawable/ic_account_circle_black_48dp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/first_name_recycler"
            android:layout_toRightOf="@+id/icon"
            android:layout_alignParentTop="true"
            android:textSize="20sp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/last_name_recycler"
            android:layout_toRightOf="@+id/first_name_recycler"
            android:layout_toEndOf="@+id/first_name_recycler"
            android:paddingLeft="7dp"
            android:textSize="20sp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/department_recycler"
            android:textSize="20sp"
            android:layout_centerVertical="true"
            android:layout_below="@+id/first_name_recycler"
            android:layout_toRightOf="@+id/icon"
            android:layout_toEndOf="@+id/icon" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/workplace_recycler"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/department_recycler"
            android:layout_toEndOf="@+id/department_recycler"
            android:layout_below="@+id/last_name_recycler"
            android:paddingLeft="7dp"
            android:textSize="20sp"
            />

    </RelativeLayout>

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

</LinearLayout>


未显示的
TextView
是Workplace。

我几乎可以肯定您的布局写得很糟糕,并且
first\u name\u recycler
中的本地化文本扩展可能会导致其他TextView的高度或宽度为0。基本上,如果其中一个文本视图太大,则没有空间容纳其他文本视图。 尝试更简单的布局,例如:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:padding="16dp">

    <android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cv"
    >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/icon"
            android:src="@drawable/ic_home"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/first_name_recycler"
            android:textSize="20sp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/last_name_recycler"
            android:textSize="20sp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/department_recycler"
            android:textSize="20sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/workplace_recycler"
            android:textSize="20sp"
            />

    </LinearLayout>

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

</LinearLayout>


它应该可以工作。

哪个文本视图不显示?另外,在TextView布局中使用
tools:text=“Some test text”
,以确保布局不是问题所在。我在文章末尾提到了哪一个。工作场所是一个回收站。我以前也有过文本,但仍然没有在其他文本字段中显示。您需要更多信息吗?您确定
String personWorkplace=cursor.getString(index5)不是空字符串吗?是的,非常确定..我遗漏了什么吗?因为我已经研究这个问题至少3个小时了,我的大脑现在有点不正常:/谢谢你的回答,但它仍然不起作用,而且这个设计与我试图实现的设计不同