简体   繁体   English

自定义适配器 - Android Studio

[英]Custom Adapter - Android Studio

So i tried to do a custom adapter, but even tho there are no errors and even tho arrayList is not empty -i am sure about that i can print something from it-, it's not working, so here is my customAdapter class:所以我尝试做一个自定义适配器,但即使没有错误,即使 arrayList 不是空的 - 我确信我可以从中打印一些东西 - 它不起作用,所以这是我的 customAdapter class:

public class CurrentListingsCustomAdapter extends ArrayAdapter<CurrentListingsClass> {

    public ArrayList<CurrentListingsClass> currentListingsClassArrayList;
    public Activity context;

    public CurrentListingsCustomAdapter(ArrayList<CurrentListingsClass> currentListingsClassArrayList, Activity context) {
        super(context, R.layout.custom_view, currentListingsClassArrayList);
        this.currentListingsClassArrayList = currentListingsClassArrayList;
        this.context = context;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        LayoutInflater layoutInflater = context.getLayoutInflater();
        View customView = layoutInflater.inflate(R.layout.custom_view, null, true);

        TextView nameView = customView.findViewById(R.id.customTextView);
        nameView.setText(currentListingsClassArrayList.get(position).getDetails());

        return customView;
    }
}

here is my custom_view.xml:这是我的 custom_view.xml:

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

    <TextView
        android:id="@+id/customTextView"
        android:layout_width="match_parent"
        android:layout_height="53dp"
        android:gravity="center|center_horizontal"
        android:text="TextView"
        android:textSize="24sp" />
</LinearLayout>

thanks in advance提前致谢

Override this method in your class like this.像这样在您的 class 中覆盖此方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM