admin管理员组

文章数量:1405636

I tried to make an android App in Android Studio. For some reason there are always errors. It started with it not being collapsible and after more hours than I want to admit of trying, I think I screwed the code up so bad that I can't make it work anymore. I know I have many files of code included in this question and if that is too much for a question I understand. I feel really bad to slam so much on all of you but I don't know what else to do anymore.

For better understanding what the goal is I added a picture i drew in Paint that originally should help me untangle this mess. the left shows what file belongs to which part of the Emergency numbers since I made 2 tabs, and the right shows how I was planning on making the Internship numbers.

This is hard to answer since in the last 6-8hrs I changed a lot of my code. I tried to rename TextViews so it won't mess with the other tab anymore, I tried to make additional adapters because it started saying I could not make it work. At this moment I seem to have the names wrong again and the collapsibility is not working anymore. I hate to admit it but I try to be as open and honest here as possible, at a point I even tried to debug it with AI (not to everyone especially me DO NEVER do that). It only made it worse and left me at the end so confused that I'd even believe you that the code creates a real pink elephant. I would absolutely understand if you guys tell me this is too much for a forum like this and I apologize if it is. I am absolutely feeling terrible to put so much work in front of this community but I am also really desperate.

at this very moment the error is the displaying wrong, the collapsibility that is not working and the following error codes:

C:\Users\ka_de\AndroidStudioProjects\OaklandsInterns\app\src\main\java\com\goldenegg\oaklandsinterns\adapter\LocationViewHolder.java:35: error: cannot find symbol holder.locationNameTextView.setText(locationItem.getLocationName()); ^ symbol: method getLocationName() location: variable locationItem of type LocationItem

C:\Users\ka_de\AndroidStudioProjects\OaklandsInterns\app\src\main\java\com\goldenegg\oaklandsinterns\adapter\LocationViewHolder.java:39: error: cannot find symbol holder.locationDescriptionTextView.setText(locationItem.getLocationDescription()); ^ symbol: method getLocationDescription() location: variable locationItem of type LocationItem

C:\Users\ka_de\AndroidStudioProjects\OaklandsInterns\app\src\main\java\com\goldenegg\oaklandsinterns\models\MyRecyclerViewAdapter.java:41: error: incompatible types: List cannot be converted to List NumberAdapter numberAdapter = new NumberAdapter(locationItem.getNumbers()); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 5 errors

C:\Users\ka_de\AndroidStudioProjects\OaklandsInterns\app\src\main\java\com\goldenegg\oaklandsinterns\InternshipNumbersFragment.java:49: error: constructor LocationAdapter in class LocationAdapter cannot be applied to given types; adapter = new LocationAdapter(locationList); ^ required: Context,List found: List reason: actual and formal argument lists differ in length

Now where you know what I was trying to do I would add a Plethora of code, that pretty much includes the parts in the picture but only the interns Numbers part since I hope I didn't completely destroy the other tab. I hope I didn't fet anything important or added something unimportant. thank you so so much everyone who takes the time reading this far:

InternshipNumbersFragment:

package com.goldenegg.oaklandsinterns;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.goldenegg.oaklandsinterns.adapter.LocationAdapter;
import com.goldenegg.oaklandsinterns.models.LocationDetails;
import com.goldenegg.oaklandsinterns.models.LocationItem;
import com.goldenegg.oaklandsinterns.models.MyRecyclerViewAdapter;
import com.goldenegg.oaklandsinterns.models.NumberItem;

import java.util.ArrayList;
import java.util.List;


public class InternshipNumbersFragment extends Fragment {

    private RecyclerView recyclerView;
    private LocationAdapter adapter;
    private List<LocationItem> locationList;

    public InternshipNumbersFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_official_numbers, container, false);

        // Initialize the RecyclerView
        recyclerView = view.findViewById(R.id.rvNumbers);

        // Get the list of locations from LocationDetails
        locationList = LocationDetails.getLocationList();  // Make sure LocationDetails returns LocationItem

        // Set up the RecyclerView layout manager
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // Use a custom adapter that handles LocationItem objects
        adapter = new LocationAdapter(locationList);
        recyclerView.setAdapter(adapter);

        return view;
    }
}

MyRecyclerViewAdapter

package com.goldenegg.oaklandsinterns.models;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.goldenegg.oaklandsinterns.R;
import com.goldenegg.oaklandsinterns.adapter.NumberAdapter;
import java.util.List;

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> {

    private Context context;
    private List<LocationItem> locationList;

    public MyRecyclerViewAdapter(Context context, List<LocationItem> locationList) {
        this.context = context;
        this.locationList = locationList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_location, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        LocationItem locationItem = locationList.get(position);

        holder.locationName.setText(locationItem.getName());
        holder.locationDescription.setText(locationItem.getNumber()); // Assuming description is in number for now.

        // Set up nested RecyclerView for internship numbers
        NumberAdapter numberAdapter = new NumberAdapter(locationItem.getNumbers());
        holder.numbersRecyclerView.setLayoutManager(new LinearLayoutManager(context));
        holder.numbersRecyclerView.setAdapter(numberAdapter);

        // Toggle visibility of details and numbers
        holder.locationDetails.setVisibility(locationItem.isDetailsVisible() ? View.VISIBLE : View.GONE);
        holder.numbersRecyclerView.setVisibility(locationItem.isDetailsVisible() ? View.VISIBLE : View.GONE);
        holder.arrowRight.setVisibility(locationItem.isDetailsVisible() ? View.GONE : View.VISIBLE);
        holder.arrowDown.setVisibility(locationItem.isDetailsVisible() ? View.VISIBLE : View.GONE);

        holder.itemView.setOnClickListener(v -> {
            locationItem.setDetailsVisible(!locationItem.isDetailsVisible());
            notifyItemChanged(position);
        });
    }

    @Override
    public int getItemCount() {
        return locationList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView locationName;
        TextView locationDescription;
        LinearLayout locationDetails;
        RecyclerView numbersRecyclerView;
        ImageButton arrowRight;
        ImageButton arrowDown;

        public ViewHolder(View itemView) {
            super(itemView);
            locationName = itemView.findViewById(R.id.location_name);
            locationDescription = itemView.findViewById(R.id.location_description);
            locationDetails = itemView.findViewById(R.id.location_details);
            numbersRecyclerView = itemView.findViewById(R.id.numbers_recycler_view);
            arrowRight = itemView.findViewById(R.id.arrow_right);
            arrowDown = itemView.findViewById(R.id.arrow_down);
        }
    }
}

fragment_internship_numbers.xml

<androidx.cardview.widget.CardView xmlns:android=";
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:elevation="2dp">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:id="@+id/location_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Location Name"
            android:textSize="18sp" />

        <LinearLayout
            android:id="@+id/location_details"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone">

            <TextView
                android:id="@+id/location_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Location Description"
                android:textSize="14sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/numbers_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end">

            <ImageButton
                android:id="@+id/arrow_right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/baseline_arrow_right_24"
                android:visibility="visible" />

            <ImageButton
                android:id="@+id/arrow_down"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/baseline_arrow_drop_down_24"
                android:visibility="gone" />
        </LinearLayout>

    </LinearLayout>
</androidx.cardview.widget.CardView>

LocationItem

package com.goldenegg.oaklandsinterns.models;

import java.util.List;

public class LocationItem {
    private String name;
    private String description; // Renamed 'number' to 'description'
    private List<InternshipNumberItem> numbers;
    private boolean detailsVisible;

    public LocationItem(String name, String description, List<InternshipNumberItem> numbers) {
        this.name = name;
        this.description = description; // Corrected assignment
        this.numbers = numbers;
        this.detailsVisible = false;
    }

    // Getters and setters
    public String getName() {
        return name;
    }

    public String getDescription() { // Renamed 'getNumber' to 'getDescription'
        return description;
    }

    public List<InternshipNumberItem> getNumbers() {
        return numbers;
    }

    public boolean isDetailsVisible() {
        return detailsVisible;
    }

    public void setDetailsVisible(boolean detailsVisible) {
        this.detailsVisible = detailsVisible;
    }
}

LocationDetails

package com.goldenegg.oaklandsinterns.models;  // Adjust package name as needed

import com.goldenegg.oaklandsinterns.models.LocationItem;
import com.goldenegg.oaklandsinterns.models.LocationItem;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LocationDetails {

    // This method creates and returns a list of LocationItem objects
    public static List<LocationItem> getLocationList() {
        List<LocationItem> locationList = new ArrayList<>();

        // You can add more locations here in the same way
        // Example: Adding "Columbus, OH"
        List<InternshipNumberItem> columbusNumbers = new ArrayList<>();
        columbusNumbers.add(new InternshipNumberItem("Interns House Girls", "NA", "1118E Dunedin Rd, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Interns House Boys (Bogdan's House)", "NA", "3278 Atwood Terrace, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Nursery", "(614) 268-3511", "1156 Oakland Park Ave, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Pharmacy (Oakland Park Pharmacy)", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Urgent Care (Hometown Urgent Care)", "(614) 681-1100", "1615 Morse Rd, Columbus, 43229"));
        columbusNumbers.add(new InternshipNumberItem("Hospital (OhioHealth Riverside)", "(614) 566-5000", "3535 Olentangy River Rd, Columbus, 43214"));
        columbusNumbers.add(new InternshipNumberItem("Police (Mifflin Twp Police Office)", "(614) 471-3548", "2455 Agler Rd, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Fire Department(Columbus Fire Station 16)", "(614) 221-3132", "1465 Oakland Park Ave, Columbus, 43224"));
        columbusNumbers.add(new InternshipNumberItem("Post Office", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));

        // Create LocationItem for "Columbus, OH"
        LocationItem columbus = new LocationItem("Columbus", "Nursery and nearby services", columbusNumbers);

        // Adding Columbus location to the list
        locationList.add(columbus);

        // Sample data for "New Albany, OH"
        List<InternshipNumberItem> delawareNumbers = new ArrayList<>();
        delawareNumbers.add(new InternshipNumberItem("Interns House Girls", "NA", "1118E Dunedin Rd, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Interns House Boys (Bogdan's House)", "NA", "3278 Atwood Terrace, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Nursery", "(614) 268-3511", "1156 Oakland Park Ave, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Pharmacy (Oakland Park Pharmacy)", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Urgent Care (Hometown Urgent Care)", "(614) 681-1100", "1615 Morse Rd, Columbus, 43229"));
        delawareNumbers.add(new InternshipNumberItem("Hospital (OhioHealth Riverside)", "(614) 566-5000", "3535 Olentangy River Rd, Columbus, 43214"));
        delawareNumbers.add(new InternshipNumberItem("Police (Mifflin Twp Police Office)", "(614) 471-3548", "2455 Agler Rd, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Fire Department(Columbus Fire Station 16)", "(614) 221-3132", "1465 Oakland Park Ave, Columbus, 43224"));
        delawareNumbers.add(new InternshipNumberItem("Post Office", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));

        // Create LocationItem for "New Albany, OH"
        LocationItem delaware = new LocationItem("Delaware", "Nursery and nearby services", delawareNumbers);

        // Sample data for "New Albany, OH"
        List<InternshipNumberItem> newAlbanyNumbers = new ArrayList<>();
        newAlbanyNumbers.add(new InternshipNumberItem("Interns House Girls", "NA", "1118E Dunedin Rd, Columbus, 43224"));
        newAlbanyNumbers.add(new InternshipNumberItem("Pharmacy (Oakland Park Pharmacy)", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));
        newAlbanyNumbers.add(new InternshipNumberItem("Urgent Care (Hometown Urgent Care)", "(614) 681-1100", "1615 Morse Rd, Columbus, 43229"));
        newAlbanyNumbers.add(new InternshipNumberItem("Hospital (OhioHealth Riverside)", "(614) 566-5000", "3535 Olentangy River Rd, Columbus, 43214"));
        newAlbanyNumbers.add(new InternshipNumberItem("Police (Mifflin Twp Police Office)", "(614) 471-3548", "2455 Agler Rd, Columbus, 43224"));
        newAlbanyNumbers.add(new InternshipNumberItem("Fire Department(Columbus Fire Station 16)", "(614) 221-3132", "1465 Oakland Park Ave, Columbus, 43224"));
        newAlbanyNumbers.add(new InternshipNumberItem("Post Office", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));


        // Create LocationItem for "New Albany, OH"
        LocationItem newAlbany = new LocationItem("New Albany", "Nursery and nearby services", newAlbanyNumbers);

        // Adding New Albany location to the list
        locationList.add(newAlbany);

        // Sample data for "New Albany, OH"
        List<InternshipNumberItem> dublinNumbers = new ArrayList<>();
        dublinNumbers.add(new InternshipNumberItem("Interns House Girls", "NA", "1118E Dunedin Rd, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Interns House Boys (Bogdan's House)", "NA", "3278 Atwood Terrace, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Nursery", "(614) 268-3511", "1156 Oakland Park Ave, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Pharmacy (Oakland Park Pharmacy)", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Urgent Care (Hometown Urgent Care)", "(614) 681-1100", "1615 Morse Rd, Columbus, 43229"));
        dublinNumbers.add(new InternshipNumberItem("Hospital (OhioHealth Riverside)", "(614) 566-5000", "3535 Olentangy River Rd, Columbus, 43214"));
        dublinNumbers.add(new InternshipNumberItem("Police (Mifflin Twp Police Office)", "(614) 471-3548", "2455 Agler Rd, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Fire Department(Columbus Fire Station 16)", "(614) 221-3132", "1465 Oakland Park Ave, Columbus, 43224"));
        dublinNumbers.add(new InternshipNumberItem("Post Office", "(614) 262-8719", "1486 Oakland Park Ave, Columbus, 43224"));


        // Create LocationItem for "New Albany, OH"
        LocationItem dublin = new LocationItem("Dublin", "Nursery and nearby services", dublinNumbers);

        // Adding New Albany location to the list
        locationList.add(newAlbany);


        // Adding New Albany location to the list
        locationList.add(delaware);




        // Return the list of locations
        return locationList;
    }
}

InternshipNumberItem

package com.goldenegg.oaklandsinterns.models;

public class InternshipNumberItem extends NumberItem {
    public InternshipNumberItem(String name, String number, String address) {
        super(name, number, address);
    }
}

LocationViewHolder

package com.goldenegg.oaklandsinterns.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.LinearLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.goldenegg.oaklandsinterns.R;
import com.goldenegg.oaklandsinterns.models.LocationItem;

import java.util.List;

public class LocationViewHolder extends RecyclerView.Adapter<LocationViewHolder.LocationHolder> {

    private List<LocationItem> locationItems;

    public LocationViewHolder(List<LocationItem> locationItems) {
        this.locationItems = locationItems;
    }

    @Override
    public LocationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_location, parent, false);  // This refers to your item_location.xml
        return new LocationHolder(itemView);
    }

    @Override
    public void onBindViewHolder(LocationHolder holder, int position) {
        LocationItem locationItem = locationItems.get(position);

        // Set the location name
        holder.locationNameTextView.setText(locationItem.getLocationName());

        // Toggle visibility of location details when clicked
        holder.locationDetailsLayout.setVisibility(locationItem.isDetailsVisible() ? View.VISIBLE : View.GONE);
        holder.locationDescriptionTextView.setText(locationItem.getLocationDescription());

        // Set up the arrow buttons
        holder.arrowRight.setVisibility(locationItem.isDetailsVisible() ? View.GONE : View.VISIBLE);
        holder.arrowDown.setVisibility(locationItem.isDetailsVisible() ? View.VISIBLE : View.GONE);

        // Handle the arrow click to toggle visibility of the details
        holder.arrowRight.setOnClickListener(v -> {
            locationItem.setDetailsVisible(true);
            notifyItemChanged(position);  // Notify the adapter to refresh the item
        });

        holder.arrowDown.setOnClickListener(v -> {
            locationItem.setDetailsVisible(false);
            notifyItemChanged(position);  // Notify the adapter to refresh the item
        });
    }

    @Override
    public int getItemCount() {
        return locationItems.size();
    }

    // ViewHolder for each location item
    public static class LocationHolder extends RecyclerView.ViewHolder {
        TextView locationNameTextView;
        TextView locationDescriptionTextView;
        LinearLayout locationDetailsLayout;
        ImageButton arrowRight;
        ImageButton arrowDown;

        public LocationHolder(View itemView) {
            super(itemView);
            locationNameTextView = itemView.findViewById(R.id.location_name);
            locationDescriptionTextView = itemView.findViewById(R.id.location_description);
            locationDetailsLayout = itemView.findViewById(R.id.location_details);
            arrowRight = itemView.findViewById(R.id.arrow_right);
            arrowDown = itemView.findViewById(R.id.arrow_down);
        }
    }
}

LocationDetailAdapter

package com.goldenegg.oaklandsinterns.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.goldenegg.oaklandsinterns.R;
import com.goldenegg.oaklandsinterns.models.InternshipNumberItem;
import java.util.List;

public class LocationDetailAdapter extends RecyclerView.Adapter<LocationDetailAdapter.ViewHolder> {

    private List<InternshipNumberItem> details;

    public LocationDetailAdapter(List<InternshipNumberItem> details) {
        this.details = details;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_location_detail, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        InternshipNumberItem detail = details.get(position);
        
        holder.nameView.setText(detail.getNumberName());
        holder.numberView.setText(detail.getNumberValue());
        holder.addressView.setText(detail.getAddress());
    }

    @Override
    public int getItemCount() {
        return details.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView nameView;
        TextView numberView;
        TextView addressView;

        ViewHolder(View itemView) {
            super(itemView);
            nameView = itemView.findViewById(R.id.detail_name);
            numberView = itemView.findViewById(R.id.detail_number);
            addressView = itemView.findViewById(R.id.detail_address);
        }
    }
}

本文标签: javaWhy are my Emergency numbers not displayed in a collapsible form by locationStack Overflow