Listview는 목록의 모든 항목에서 마지막 항목의 제목과 주소를 표시합니다.

신디 B

나는 안드로이드를 처음 사용합니다. 탐색 서랍을 만들고 조각을 추가하여 동적으로 메뉴를 만들었습니다. 이제 각 메뉴에 대해 arrayadapter 클래스를 사용하여 사용자 지정 목록보기를 만들고 싶습니다. 구현했지만 문제는 목록의 모든 항목에서 제목과 주소가 동일하다는 것입니다. 목록에는 마지막 항목 만 표시됩니다. 누구든지 나를 도울 수 있습니까! 해결책을 찾을 수 없습니다. 다음은 몇 가지 코드와 사진입니다.

import static com.example.user.appsightseeing.R.layout;



public class ParksFragment extends Fragment {
    private ArrayList<Park> parks = new ArrayList<>();


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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(layout.fragment_parks, container, false);

        parks.add(new Park("Artificial Lake of Tirana", "The Grand Park of Tirana, also known as the Tirana Park on the Artificial Lake or even the Park of Saint Procopius, is a 230 hectare public park situated on the southern part of Tirana.",
                "At the end of Rruga Sami Frasheri.", R.drawable.artificiallake));
        parks.add(new Park("Zoo park", "The only one of its kind in Albania, Tirana Zoo is concentrated in an area of \u200B\u200B7 hectares in the southern part of town, between the Grand Park and the Botanic Garden of Tirana . The zoo was established in 1966.",
                "Near Rruga Liqeni i Thate", R.drawable.zoopark));
        parks.add(new Park("Memorial park of the Cemetery of the Nation's Martyrs", "The National Martyrs Cemetery of Albania is the largest cemetery in Albania, located on a hill overlooking Tirana. The \"Mother Albania\" statue is located at the Cemetery.",
                "Near street Rruga Ligor Lubonja", R.drawable.memorialpark));
        parks.add(new Park("Kashar park", "The main core of Kashar’s Park, is the Reservoir of Purez- Kus. The reservoir and its surrounding territory are considered as one of the most picturesque and biologically unsoiled suburbs of Tirana.",
                "Kashar", R.drawable.kasharpark));
        parks.add(new Park("Vaqarr park", "The second park in Vaqarr, is a recreational area of 97 ha, that is more than useful to inhabitants in Tirana.",
                "Vaqarr", R.drawable.vaqarripark));
        parks.add(new Park("Farka Lake park", "To the East of the East of Tirana’s city center, Lake Farka is a local favorite for waterborne fun in Summer. Picnicking, jet and water skiing, swimming, boating, all the usual wet sports suspects.",
                "At Lake of Farka, near Rruga Pjeter Budi", R.drawable.farkapark));
        parks.add(new Park("Peza park", "Peza, a village approximately 20 minutes from the center of Tirana, is a popular place for locals to go for a coffee or lunch on the weekends to escape the city.",
                "Peze", R.drawable.pezapark));
        parks.add(new Park("Dajti Recreative park", "This park is one of the components of Dajti National Park, located 26 km east of Tirana and 50 km from \"Mother Teresa\" airport. This place is very frequented by tourists and is also known as the \"Natural Balcon of Tirana\" which offers recreation and accommodation facilities for tourists.",
                "Dajti mountain", R.drawable.dajtirecreative));
        parks.add(new Park("Dajti National park", "Dajti National Park is very important on local, national and regional level, for its biodiversity, landscape, recreational and cultural values. Among others it is considered as a live museum of the natural vertical structure of vegetation.",
                "Dajti mountain", R.drawable.dajtinational));
        parks.add(new Park("Botanic garden", "The Botanical Gardens of Tirana are scenic botanical gardens located in southern Tirana, Albania. It is the only botanical garden in Albania. Construction commenced in 1964, with the original site covering approximately 15 hectares.",
                "Near Zoo park", R.drawable.botanicpark));
        parks.add(new Park("Rinia park", "The park, 500 metres (1,600 ft) from the central square, was built in 1950[5] as part of a major urban development program which developed after World War II. It was initially a pleasant family park where inhabitants of Tirana could take their children.",
                "Near Bulevardi Deshmoret e Kombit and near Rruga Myslym Shyri", R.drawable.riniapark));

        ArrayAdapter<Park> adapter = new parkArrayAdapter(getActivity(), 0, parks);


        ListView listView = (ListView) rootView.findViewById(R.id.customListView);
        listView.setAdapter(adapter);
        return rootView;

        //add event listener so we can handle clicks
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
    }
}

arrayadapter 클래스 :

import java.util.List;



    public class parkArrayAdapter extends ArrayAdapter<Park> {

        private Context context;
        private List<Park> parks;
        private AnimatedStateListDrawable inflater;

        //constructor, call on creation
        public parkArrayAdapter(Context context, int resource, ArrayList<Park> objects) {
            super(context, resource, objects);

            this.context = context;
            this.parks = objects;
        }

        //called when rendering the list
        @NonNull
        public View getView(int position, View convertView, ViewGroup parent) {


            //get the park we are displaying
            Park par = parks.get(position);
            //get the inflater and inflate the XML layout for each item
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.park_layout, null);

            TextView title = (TextView) view.findViewById(R.id.p_title);
            TextView description = (TextView) view.findViewById(R.id.p_description);
            TextView streetname = (TextView) view.findViewById(R.id.address);
            ImageView image = (ImageView) view.findViewById(R.id.image);

            //set title and description
            String titleT = par.getPark_title();
            title.setText(titleT);

            //display trimmed excerpt for description
            int descriptionLength = par.getPark_description().length();
            if(descriptionLength >= 100){
                String descriptionTrim = par.getPark_description().substring(0, 100) + "...";
                description.setText(descriptionTrim);
            }else{
                description.setText(par.getPark_description());
            }

            streetname.setText(par.getPark_streetname());

            //get the image associated with this park
            int imageID = context.getResources().getIdentifier(String.valueOf(par.getPark_image()), "drawable", context.getPackageName());
            image.setImageResource(imageID);

            return view;
        }
    }

파크 클래스 :

public class Park {

    private static String title;
    private String description;
    private static String streetname;
    private int image;


    public Park(String title, String description, String streetname, int image){
        this.title = title;
        this.description = description;
        this.streetname = streetname;
        this.image = image;

    }

    public static String getPark_title() { return title; }

    public String getPark_description() {
        return description;
    }

    public static String getPark_streetname() {
        return streetname;
    }

    public int getPark_image() {
        return image;
    }
}

행의 공원 레이아웃 :

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginRight="10dp"
        android:contentDescription="Park Image" />

    <LinearLayout
        android:id="@+id/infoSection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/image"
        android:orientation="vertical">

        <TextView
            android:id="@+id/p_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:text="Park Title"
            android:textColor="@android:color/black"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/p_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="5dp"
            android:text="Park Description"
            android:textColor="@android:color/black"
            android:textSize="15sp" />

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/addressSection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/infoSection"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">

        <TextView
            android:id="@+id/address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:text="Address:"
            android:textColor="@android:color/black" />

    </RelativeLayout>

</RelativeLayout>

모든 항목에 동일한 제목과 주소가있는 목록보기의 스크린 샷

CanDroid

이것은 Android와 관련이 없습니다. 클래스를 확인하면 제목 및 거리 이름 필드와 해당 getter 메서드를 정적으로 설명했음을 알 수 있습니다. 어댑터에서 값을 얻을 때 모든 제목 및 거리 이름 필드에 대해 동일하기 때문에이 문제가 발생합니다. 모든 플랫폼의 모든 애플리케이션에서 정적 멤버와 인스턴스 멤버 간의 차이점을 설명하는 좋은 예를 만들었습니다. 인스턴스 멤버는 메모리의 다른 주소에 있지만 정적 멤버는 동일한 주소에 있으며 정적 멤버에 값을 할당하면 모든 정적 멤버의 값이 메모리의 동일한 위치에 있기 때문에 변경됩니다. "정적"단어를 삭제하면 목록보기가 잘 작동합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

목록의 마지막 요소를 제외하고 목록의 모든 항목에 대해 똑같이 할 수있는 방법이 있습니까?

분류에서Dev

드롭 다운 목록에 주어진 목록의 모든 항목이 있는지 확인하는 방법

분류에서Dev

Kotlin 배열의 모든 항목에는 항상 마지막 항목이 포함됩니다.

분류에서Dev

vuejs의 목록 항목에서 마지막 드롭 다운 구분선 클래스를 제거하는 방법

분류에서Dev

목록의 모든 항목을 목록의 다른 모든 항목과 비교하여 정의 된 간격에 속하는지 확인

분류에서Dev

Listview의 Gridview는 모든 라인에 대해 마지막 gridview 항목을 반복합니다.

분류에서Dev

파이썬에서 목록을 재귀 적으로 정의하면 목록의 모든 항목이 마지막 항목으로 대체됩니다.

분류에서Dev

첫 번째 항목에 영향을주는 목록보기에서 마지막 항목의 색상 변경

분류에서Dev

Linq, 다른 목록의 마지막 항목에 목록 결합

분류에서Dev

Linq, 다른 목록의 마지막 항목에 목록 결합

분류에서Dev

경로 Powershell에서 마지막 슬래시 이후의 모든 항목을 제거하는 방법

분류에서Dev

모든 목록에서 n [1]과 같은 목록에서 일부 요소가 필요하고 마지막 항목은 별도의 [-1]

분류에서Dev

Android 사용자 정의 목록보기는 첫 번째 위치에 마지막 항목을 표시합니다.

분류에서Dev

Android는 전체 목록을 다시 그리지 않고 모든 항목의 recyclerview에서 textview를 변경합니다.

분류에서Dev

첫 번째 대시 앞과 마지막 대시 뒤의 모든 항목을 제거하려면 SED 또는 AWK

분류에서Dev

listView의 첫 번째 항목과 마지막 항목이 동일합니다.

분류에서Dev

터미널에서 마지막 ":"앞의 모든 항목 제거

분류에서Dev

pnp powershell을 사용하여 SharePoint Online 목록에서 마지막으로 수정 된 항목의 항목 ID를 얻는 방법은 무엇입니까?

분류에서Dev

마지막 마지막 슬래시와 해당 MySQL 쿼리 이후의 모든 항목을 제거합니다.

분류에서Dev

Android-목록의 끝에 마지막 항목 추가 ListView

분류에서Dev

PHP 정규식은 후행 슬래시를 제외하고 마지막 슬래시 앞의 모든 항목과 일치합니다.

분류에서Dev

SwiftUI의 마지막 목록 항목에서 구분선을 제거하는 방법은 무엇입니까?

분류에서Dev

한 목록의 모든 항목이 다른 목록에 있는지 확인하는 한 줄 논리 테스트

분류에서Dev

마지막 HTML 목록 항목의 둥근 하단 모서리?

분류에서Dev

Laravel에서 foreachloop의 마지막 항목에서 쉼표를 제거하는 방법은 무엇입니까?

분류에서Dev

Owl Carousel 2의 보이는 항목 중 첫 번째 항목과 마지막 항목에 클래스를 추가하려면 어떻게해야합니까?

분류에서Dev

항상 Android의 ListView에있는 목록에서 마지막 값을 가져옵니다.

분류에서Dev

cwac-merge-1.0.4 jar를 사용하여 자식 ListView의 모든 목록 항목을 표시하는 방법

분류에서Dev

cwac-merge-1.0.4 jar를 사용하여 자식 ListView의 모든 목록 항목을 표시하는 방법

Related 관련 기사

  1. 1

    목록의 마지막 요소를 제외하고 목록의 모든 항목에 대해 똑같이 할 수있는 방법이 있습니까?

  2. 2

    드롭 다운 목록에 주어진 목록의 모든 항목이 있는지 확인하는 방법

  3. 3

    Kotlin 배열의 모든 항목에는 항상 마지막 항목이 포함됩니다.

  4. 4

    vuejs의 목록 항목에서 마지막 드롭 다운 구분선 클래스를 제거하는 방법

  5. 5

    목록의 모든 항목을 목록의 다른 모든 항목과 비교하여 정의 된 간격에 속하는지 확인

  6. 6

    Listview의 Gridview는 모든 라인에 대해 마지막 gridview 항목을 반복합니다.

  7. 7

    파이썬에서 목록을 재귀 적으로 정의하면 목록의 모든 항목이 마지막 항목으로 대체됩니다.

  8. 8

    첫 번째 항목에 영향을주는 목록보기에서 마지막 항목의 색상 변경

  9. 9

    Linq, 다른 목록의 마지막 항목에 목록 결합

  10. 10

    Linq, 다른 목록의 마지막 항목에 목록 결합

  11. 11

    경로 Powershell에서 마지막 슬래시 이후의 모든 항목을 제거하는 방법

  12. 12

    모든 목록에서 n [1]과 같은 목록에서 일부 요소가 필요하고 마지막 항목은 별도의 [-1]

  13. 13

    Android 사용자 정의 목록보기는 첫 번째 위치에 마지막 항목을 표시합니다.

  14. 14

    Android는 전체 목록을 다시 그리지 않고 모든 항목의 recyclerview에서 textview를 변경합니다.

  15. 15

    첫 번째 대시 앞과 마지막 대시 뒤의 모든 항목을 제거하려면 SED 또는 AWK

  16. 16

    listView의 첫 번째 항목과 마지막 항목이 동일합니다.

  17. 17

    터미널에서 마지막 ":"앞의 모든 항목 제거

  18. 18

    pnp powershell을 사용하여 SharePoint Online 목록에서 마지막으로 수정 된 항목의 항목 ID를 얻는 방법은 무엇입니까?

  19. 19

    마지막 마지막 슬래시와 해당 MySQL 쿼리 이후의 모든 항목을 제거합니다.

  20. 20

    Android-목록의 끝에 마지막 항목 추가 ListView

  21. 21

    PHP 정규식은 후행 슬래시를 제외하고 마지막 슬래시 앞의 모든 항목과 일치합니다.

  22. 22

    SwiftUI의 마지막 목록 항목에서 구분선을 제거하는 방법은 무엇입니까?

  23. 23

    한 목록의 모든 항목이 다른 목록에 있는지 확인하는 한 줄 논리 테스트

  24. 24

    마지막 HTML 목록 항목의 둥근 하단 모서리?

  25. 25

    Laravel에서 foreachloop의 마지막 항목에서 쉼표를 제거하는 방법은 무엇입니까?

  26. 26

    Owl Carousel 2의 보이는 항목 중 첫 번째 항목과 마지막 항목에 클래스를 추가하려면 어떻게해야합니까?

  27. 27

    항상 Android의 ListView에있는 목록에서 마지막 값을 가져옵니다.

  28. 28

    cwac-merge-1.0.4 jar를 사용하여 자식 ListView의 모든 목록 항목을 표시하는 방법

  29. 29

    cwac-merge-1.0.4 jar를 사용하여 자식 ListView의 모든 목록 항목을 표시하는 방법

뜨겁다태그

보관