Java MultiListView只显示一个TextView
我正在编写一个每行有2个文本视图的列表视图,但是当我执行时,我只得到一个文本视图 这是我的适配器扩展基本适配器Java MultiListView只显示一个TextView,java,android,listview,adapter,baseadapter,Java,Android,Listview,Adapter,Baseadapter,我正在编写一个每行有2个文本视图的列表视图,但是当我执行时,我只得到一个文本视图 这是我的适配器扩展基本适配器 public class GlossaryListViewAdapter extends BaseAdapter { List<Glossary_Entry> glossary_entryList; Context context; public GlossaryListViewAdapter(Context context,List<Glossary_Entry
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);
}
}
}
这是我的glossary\u single\u 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>
当我执行时,请帮助我每行只获得一个文本视图…显然,我需要在第二个文本视图中将文本颜色更改为黑色。文字就在那里,根本看不见
<LinearLayout xmlns:android="http:// schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
您需要在layout R.layout.glossary_single_row之后正确地显示您的xmlplz共享。显示您的xml我认为问题在于您的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>
<LinearLayout xmlns:android="http:// schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
<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