MultiListView 只显示一个TextView

MultiListView displays only one TextView

我正在编写一个每行有 2 个 TextView 的 ListView,但是当我执行时,我只得到一个 TextView。

这是我的适配器扩展基础适配器

public class GlossaryListViewAdapter extends BaseAdapter {

List<Glossary_Entry> glossary_entryList;
Context context;

public GlossaryListViewAdapter(Context context,List<Glossary_Entry> glossary_entryList){
    this.glossary_entryList = glossary_entryList;
    this.context = context;
}

@Override
public int getCount() {
    return glossary_entryList.size();
}

@Override
public Object getItem(int postion) {
    return glossary_entryList.get(postion);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View view, ViewGroup viewGroup) {

    ViewHolder viewHolder;

    if(view == null){
        view = LayoutInflater.from(context).inflate(R.layout.glossary_single_row,viewGroup,false);
        viewHolder = new ViewHolder(view);
        view.setTag(viewHolder);
    }else{
        viewHolder = (ViewHolder)view.getTag();
    }


     viewHolder.titleTextView.setText(glossary_entryList.get(position).getTitle());
    viewHolder.definitionTextView.setText(glossary_entryList.get(position).getDefinition());


    return view;
}

private static class ViewHolder{
    TextView titleTextView;
    TextView definitionTextView;

    public ViewHolder(View view){
        titleTextView = (TextView)view.findViewById(R.id.glossary_title_textview);
        definitionTextView = (TextView)view.findViewById(R.id.glossary_word_definition_textview);
    }
}

}

这是我的 Activity 代码

public class GlossaryAcvtivity extends AppCompatActivity {

ListView glossaryListView;
ListAdapter listAdapter;
List<Glossary_Entry> glossary_entryList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_glossary);

    /**
     * Sample data
     */
    glossary_entryList = new ArrayList<>();
    glossary_entryList.add( new Glossary_Entry("Force","This is a push or push on an object.They can be duew to a phenomenon such as gravity, magnetism, or anything that might cause a mass to accelerate."));
    glossary_entryList.add( new Glossary_Entry("Motion","Change in position of an object over time, described in terms of displacement,distance,velocity,acceleration,time and speed"));
    glossary_entryList.add( new Glossary_Entry("Quantum Leap","An Abrupt transition of an electron,atom, or molecule from one quantum state to another,with the absorption or emission of a quantum"));
    glossary_entryList.add( new Glossary_Entry("Force","This is a push or push on an object.They can be duew to a phenomenon such as gravity, magnetism, or anything that might cause a mass to accelerate."));


    glossaryListView = (ListView)findViewById(R.id.glossary_list_view);
    listAdapter = new GlossaryListViewAdapter(getApplicationContext(),glossary_entryList);
    glossaryListView.setAdapter(listAdapter);


}

}

我的数据源是一个条目class

public class Glossary_Entry {

public String title;
public String definition;

public String getTitle() {
    return title;
}

public String getDefinition() {
    return definition;
}

public Glossary_Entry(String title,String definition){
    this.title = title;
    this.definition = definition;
}

}

这是我的 glossary_single_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_marginTop="10dp"
   android:layout_marginLeft="10dp"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textColor="@color/blue"
        android:textStyle="bold"
        android:textSize="16sp"
        android:layout_margin="4dp"
        android:id="@+id/glossary_title_textview"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/app_description"
        android:layout_margin="4dp"
        android:textSize="12sp"
        android:id="@+id/glossary_word_definition_textview"/>

</LinearLayout>

这是我的 glossary_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@color/white"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:id="@+id/glossary_toolbar"
        android:background="@color/colorPrimary"
        android:layout_height="?attr/actionBarSize">

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

    <ListView
        android:layout_width="match_parent"
        android:id="@+id/glossary_list_view"
        android:layout_margin="8dp"
        android:layout_below="@+id/glossary_toolbar"
        android:layout_height="wrap_content">
    </ListView>

</RelativeLayout>

执行时请帮忙我每行只有一个TextView...

显然,我需要将第二个 TextView 中的文本颜色更改为黑色。文本在那里只是不可见。

<LinearLayout xmlns:android="http://  schemas.android.com/apk/res/android" 
android:orientation="vertical"
android:layout_marginTop="10dp" 
android:layout_marginLeft="10dp"

android:layout_width="match_parent" android:layout_height="wrap_content">

<TextView android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:text="@string/app_name"
android:textColor="@color/blue" 
android:textStyle="bold" 
android:textSize="16sp" android:layout_margin="4dp"
android:id="@+id/glossary_title_textview"/>

<TextView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:text="@string/app_description"
android:layout_margin="4dp" 
android:textSize="12sp" 
android:textColor="@color/black"
android:id="@+id/glossary_word_definition_textview"/>

</LinearLayout