gpt4 book ai didi

java - Android ListView 显示不正确

转载 作者:行者123 更新时间:2023-12-01 23:10:29 25 4
gpt4 key购买 nike

我必须将 SQLite 数据库中的对象显示到 listView。我尝试了,但我找不到问题,为什么我看不到第一个对象的一半,最后一个对象的一半。可能是什么问题?屏幕:/image/KR9rf.png

适配器类别:

public class ReminderListAdapter extends ArrayAdapter<Reminder> {
private Context mContext;
private int mResource;
OnItemClickListener listener;


public ReminderListAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Reminder> objects) {
super(context, resource, objects);
mContext = context;
mResource = resource;

}

public void setListener(OnItemClickListener listener) {
this.listener = listener;
}

@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final int id = getItem(position).getId();
final String name = getItem(position).getName();
String hour = getItem(position).getHour();
String date = getItem(position).getDate();


LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(mResource, parent, false);
Button delbtn = (Button) convertView.findViewById(R.id.button4);
//Button editbtn = (Button) convertView.findViewById(R.id.button5);
final TextView resId = convertView.findViewById(R.id.textId);
final TextView resName = convertView.findViewById(R.id.textName);
final TextView resHour = convertView.findViewById(R.id.textHour);
final TextView resDate = convertView.findViewById(R.id.textDate);

resId.setText(String.valueOf(id));
resName.setText(name);
resHour.setText(hour);
resDate.setText(date);


delbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.OnItemClick(v, position, id);
}
});

return convertView;
}}

XML:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_background"
android:id="@+id/content"
android:orientation="vertical"
tools:context=".EditActivity">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@drawable/item_color_state"
app:itemTextColor="@drawable/item_color_state"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_navigation_main"
tools:layout_editor_absoluteX="4dp" />

<ListView
android:id="@+id/ListOfReminders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

我多次检查这个 xml 文件,但找不到我的错误。我将 listView 的底部限制到底部导航栏,将顶部限制到 parrent 的顶部,但它不起作用

最佳答案

我认为你应该从 ListView 中删除这一行,你的问题就可以解决。

Remove this

   app:layout_constraintBottom_toTopOf="@id/bottom_navigation"

Add this Code and your problem fully solved

   android:paddingBottom="200dp"

关于java - Android ListView 显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58379478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com