Attempting to link values in Adapter with TextView in ListView fails.

Asked 2 years ago, Updated 2 years ago, 113 views

Adapter and activity_main.xml are described as follows:
If you enable commenting out, the execution fails.

There are many methods in MainActivity.java, but
Failed when setting Adapter to ListView, or
OnCreate's setContentView(R.layout.activity_main); drops.

I looked it up in English, but it's too much for me to teach myself.

If anyone knows anything, please take care of me.

BoolAndDateAdapter.java

public classBoolAndDateBeanAdapter extensionsBaseAdapter{
    publicBoolAndDateBeanAdapter(Contextcontext){
        this.context=context;
        This.layoutInflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    Context context;
    LayoutInflater layoutInflater = null;
    ArrayList<BoolAndDateBean>beans;

    public void setBeans (ArrayList<BoolAndDateBean>beans) {
        This.beans=beans;
    }

    @ Override
    public intgetCount(){
        return beans.size();
    }

    @ Override
    publicObjectgetItem(int position){
        return beans.get(position);
    }

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

    @ Override
    publicView getView(int position, View convertView, ViewGroup parent) {
        convertView = layoutInflater.inflate(R.layout.activity_main, parent);

    //        ((TextView) convertView.findViewById(R.id.bool)) .setText(String.valueOf(beans.get(position).bool));
    //        ((TextView) convertView.findViewById(R.id.hour)) .setText(beans.get(position).hour);
    //        ((TextView) convertView.findViewById(R.id.minit)) .setText(beans.get(position).minit);
        return convertView;
    }
}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        tools:ignore="MergeRootFrame">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ToggleButton
                android: id="@+id/toggleButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textOff="off"
                android:textOn="on"
                android:visibility="invisible"/>

            <com.google.android.material.floatingactionButton.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:layout_marginStart="20sp"
                android:layout_marginLeft="20sp"
                android:layout_marginTop="20sp"
                android:layout_marginEnd="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginBottom="20sp"
                android: clickable="true"
                android: onClick="OnClick_Add"
                app: rippleColor="#00FCFC"
                app:srcCompat="@drawable/ic_add_24dp"/>
            <GridLayout
                android: id="@+id/grid"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:layout_marginTop="50dp">
                <Button
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android: id="@+id/button0"
                    android:layout_row="0"
                    android:layout_column="0">
                </Button>
                <Button
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android: id="@+id/button1"
                    android:layout_row="0"
                    android:layout_column="1">
                </Button>
                <Button
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android: id="@+id/button2"
                    android:layout_row="0"
                    android:layout_column="2">
                </Button>

                <Button
                    android: id="@+id/button3"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_row="0"
                    android:layout_column="3"></Button>
            </GridLayout>
            <ListView
                android:id="@+id/listview"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_below="@+id/grid">
                <!--<TextView-->
                    <!--android:id="@+id/bool" -->
                    <!--android:layout_width="50dp"-->
                    <!--android:layout_height="50dp"/>-->
                <!--<TextView-->
                    <!--android:id="@+id/hour" -->
                    <!--android:layout_width="50dp"-->
                    <!--android:layout_height="50dp"/>-->
                <!--<TextView-->
                    <!--android:id="@+id/minit" -->
                    <!--android:layout_width="50dp"-->
                    <!--android:layout_height="50dp"/>-->
            </ListView>

        </RelativeLayout>
    </FrameLayout>

android xml

2022-09-30 18:03

1 Answers

The reason was that there was another view in ListView.Resolved.


2022-09-30 18:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.