【发布时间】:2018-11-09 05:44:59
【问题描述】:
我正在尝试制作一个应用程序,它将借助自定义适配器在列表视图上绘制我的自定义 value_item 布局。我的 value_item 布局由 3 个水平对齐的文本视图组成。但是当我尝试在列表视图中绘制布局时,只显示第三个文本视图。我已经尝试了很多来找出问题所在,但我无法找到问题所在。 值适配器的代码如下:
public class ValueAdapter extends ArrayAdapter<Value>{
public ValueAdapter(Context context, List<Value> values)
{
super(context,0,values);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.value_item, parent, false);
}
Value channel = getItem(position);
TextView val = (TextView) listItemView.findViewById(R.id.val_view);
val.setText(channel.getval()+" ");
TextView mtime = (TextView) listItemView.findViewById(R.id.time_view);
val.setText(channel.getTime());
TextView mdate = (TextView) listItemView.findViewById(R.id.date_view);
val.setText(channel.getDate());
return listItemView;
}
}
value_item 布局的代码是:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5"
android:background="#424242"
android:padding="8dp"
android:layout_margin="3dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="25dp"
tools:text="Hello"
android:layout_marginLeft="10dp"
android:id="@+id/val_view"
/>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:textSize="24dp"
tools:text="24-12-2200"
android:id="@+id/time_view"
/>
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="match_parent"
android:textSize="24dp"
tools:text="24-12-2200"
android:id="@+id/date_view"
/>
</LinearLayout>
【问题讨论】:
标签: android xml listview arraylist custom-adapter