Android에서 조각의 정렬 문제 및 데이터 표시를 수정하는 방법은 무엇입니까?

로빈

저는 Android를 직접 배우고 있습니다. 이제 조각을 배우려고합니다. 여기에서 연락처 활동에 대한 조각을 호스팅하고 싶습니다.

2 가지 문제가 있습니다

문제 1 : 세부 정보 조각에 모든 데이터가 표시되지 않습니다.

예를 들어 내 자바 클래스에서. 새로운 Contact ( "Ron", "Thal", "+ 405-315-2827", "[email protected]")가 있습니다.

목록에는 성인 Thal이 있습니다. 그것을 클릭하면 이름, 성, 전화 및 이메일이 표시됩니다. 하지만 이름 만 표시되지만 문제 2

문제 2 : 목록 조각에서 성을 알파벳순으로 정렬했습니다. 그러나 목록 조각에서 정렬 된 목록을 사용할 때 세부 조각에 올바른 데이터가 표시되지 않습니다. 세부 조각은 순수한 Java 클래스에있는 순서대로 조각 데이터를 표시합니다. 목록에 관련 데이터를 표시해야합니다.

정렬하지 않으면 올바른 데이터가 표시되지만 목록 조각에서 성을 클릭하면 세부 조각에 이름 만 표시됩니다.

그것을 고치는 방법? 내가 착각 한 곳은?

연락 활동

public class ContactActivity extends Activity implements ContactListFragment.ContactListListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact);

    }

    @Override
    public void itemClicked(long id){
        //method also defined in the listener

        View fragmentContainer = findViewById(R.id.fragment_detail_container);
        if (fragmentContainer != null){
            ContactDetailsFragment detailsFragment = new ContactDetailsFragment();
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            detailsFragment.setContact(id);
            fragmentTransaction.replace(R.id.fragment_detail_container, detailsFragment);
            //fragmentTransaction.addToBackStack(null);
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            fragmentTransaction.commit();
        }

    }

}

연락처 정보 조각

public class ContactDetailsFragment extends Fragment {
    private long contactId;

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

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null){
            contactId = savedInstanceState.getLong("contactId");
        }
    }


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

        return inflater.inflate(R.layout.fragment_contact_details, container, false);
    }

    @Override
    public void onStart(){
        super.onStart();
        View view = getView();
        if (view != null){

            TextView FNameText = (TextView) view.findViewById(R.id.textFName);
            Contact contact = myContact[(int) contactId];
            FNameText.setText(contact.getFName());
            TextView LNameText = (TextView) view.findViewById(R.id.textLName);
            LNameText.setText(contact.getLName());
            TextView PhoneText = (TextView) view.findViewById(R.id.textPhone);
            PhoneText.setText(contact.getPhone());
            TextView EmailText = (TextView) view.findViewById(R.id.textEmail);
            EmailText.setText(contact.getEmail());

        }
    }
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState){
        savedInstanceState.putLong("contactId", contactId);
    }

    public void setContact(long id){
        this.contactId = id;
    }

}

연락처 목록 조각

public class ContactListFragment extends ListFragment {

    //ArrayAdapter<Contact> cAdapter;
    ArrayAdapter<String> cAdapter;


    interface ContactListListener{
        void itemClicked(long id);
    }
    //add listener to fragment
    private ContactListListener listener;

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


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

        //String[] lastname = new String[Contact.class]
        //cAdapter = new ArrayAdapter<>(inflater.getContext(), R.layout.fragment_contact_list, myContact);

        String[] lnames = new String[Contact.myContact.length];
        //String[] fnames = new String[Contact.myContact.length];
        for (int i = 0; i < lnames.length; i++){
            lnames[i] = Contact.myContact[i].getLName();
            //fnames[i] = myContact[i].getFName();

        }


        //ArrayAdapter<String> cAdapter;
        //ArrayAdapter<String> cAdapter;

        //cAdapter = new ArrayAdapter<>(inflater.getContext(), android.R.layout.simple_list_item_1, myContact);
        cAdapter = new ArrayAdapter<>(inflater.getContext(), android.R.layout.simple_list_item_1, lnames);
        //to sort alphabetically
        /*
        cAdapter.sort(new Comparator<Contact>() {
            @Override
            public int compare(Contact o1, Contact o2) {
                return o1.toString().compareToIgnoreCase(o2.toString());
            }
        });
        */

        cAdapter.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {

                return o1.compareTo(o2);
            }
        });

        setListAdapter(cAdapter);
        cAdapter.notifyDataSetChanged();

        return super.onCreateView(inflater, container, savedInstanceState);
    }
    @Override
    public void onAttach(Activity activity){
        super.onAttach(activity);
        this.listener = (ContactListListener) activity;
    }
    @Override
    public void onListItemClick(ListView l, View v, int position, long id){
        if (listener != null){
            listener.itemClicked(id);
        }
    }
}

조각 연락처 세부 정보 xml

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text=""
        android:id="@+id/textFName"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text=""
        android:id="@+id/textLName"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text=""
        android:id="@+id/textPhone"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text=""
        android:id="@+id/textEmail"
        />
</LinearLayout>

연락처 활동 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_contact"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:baselineAligned="false"
    tools:context="edu.uco.rawal.p5rabina.ContactActivity">
        <fragment
            class="edu.uco.rawal.p5rabina.ContactListFragment"
            android:layout_width="0dp"
            android:layout_weight ="1"
            android:layout_height="match_parent"
            android:id="@+id/contact_list_frag"/>


        <FrameLayout
            android:id="@+id/fragment_detail_container"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent"
            >

        </FrameLayout>

</LinearLayout>

Contact.java (순수 자바 클래스)

public class Contact {
    private String fname, lname, phone, email;


    public static final Contact[] myContact = {

            new Contact("Rabin", "Awal", "+405-315-0007", "[email protected]"),
            new Contact("David", "Gilmour", "+405-315-2027", "[email protected]"),
            new Contact("James", "Hetfield", "+405-315-2527", "[email protected]"),
            new Contact("Kirk", "Hammet", "+405-315-2995", "[email protected]"),
            new Contact("Tom", "Morello", "+405-315-2886", "[email protected]"),
            new Contact("Angus", "Young", "+405-315-2831", "[email protected]"),
            new Contact("Ron", "Thal", "+405-315-2827", "[email protected]")
    };



    private Contact(String fname, String lname, String phone, String email){
        this.fname = fname;
        this.lname = lname;
        this.email = email;
        this.phone = phone;
    }

    public String getFName() {
        return fname;
    }

    public String getLName() {
        return lname;
    }

    public String getEmail() {
        return email;
    }

    public String getPhone() {
        return phone;
    }
    /*

    public void setFName(String fname) {
        this.fname = fname;
    }

    public void setLName(String lname) {
        this.lname = lname;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    */

    @Override
    public String toString() {
        //return super.toString();


        return  fname.toString();
        //return this.fname;

    }


}

감사합니다

OneCricketeer

이름 만 표시됩니다.

이 때문에의 ListView에서 그 의미가 ArrayAdapter<String>됩니다 toString당신의 객체가, return fname.toString();(정말 할 수있는 return fname)

당신이 세부 조각 내부에 의미 있다면, 당신의 XML에, 각각 TextView이상적으로해야한다 android:layout_height="wrap_content"대신 match_parent. 그렇지 않으면 하나 TextView가 전체 화면을 차지합니다.

목록 조각에서 성을 알파벳순으로 성공적으로 정렬했습니다.

좋아요, 그럼 문제가 뭔지 모르겠네요 ...이게 문제라는 뜻 이었나?

cAdapter.sort(new Comparator<Contact>() {
    @Override
    public int compare(Contact o1, Contact o2) {
        return o1.toString().compareToIgnoreCase(o2.toString());
    }
});

여기에 두 개의 연락처 개체가 있습니다 ... 성을 기준으로 정렬하려면 그렇게하십시오.

cAdapter.sort(new Comparator<Contact>() {
    @Override
    public int compare(Contact c1, Contact c2) {
        return c1.getLName().compareToIgnoreCase(c2.getLName());
    }
});

이 코드와 관련하여.

   String[] lnames = new String[Contact.myContact.length];
    //String[] fnames = new String[Contact.myContact.length];
    for (int i = 0; i < lnames.length; i++){
        lnames[i] = Contact.myContact[i].getLName();
        //fnames[i] = myContact[i].getFName();

    }

성 / 이름 ArrayAdapter<Contact>Contact아닌 모든 정보를 표시하려는 경우 생성 방법을 조회하는 것이 좋습니다 .

그리고 나는 또한 getView()내에서 사용하는 것에 대해 너무 확신하지 못합니다 onStart()... 나는 당신이 onCreateView또는 에서보기를 사용해야한다고 생각합니다 onViewCreated.

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

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

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

데이터 테이블 열에서 정렬 문제 날짜를 수정하는 방법은 무엇입니까?

분류에서Dev

파일의 '문자열'에서 표시되는 데이터를 제거하는 방법은 무엇입니까?

분류에서Dev

Android에서 RecycleView의 데이터를 정렬하는 방법은 무엇입니까?

분류에서Dev

내 데이터를 재정렬하는 방법은 무엇입니까? 분할 및 조옮김

분류에서Dev

초기 데이터에 대해 정렬 화살표를 표시하는 방법은 무엇입니까?

분류에서Dev

게시물에 사용자 정의 필드 데이터를 표시하는 방법은 무엇입니까?

분류에서Dev

C #의 HtmlTable에서 데이터를 추출하고 행으로 정렬하는 방법은 무엇입니까?

분류에서Dev

반응에서 어레이의 제품 정보를 표시하는 방법은 무엇입니까?

분류에서Dev

Spring JPA에서 데이터를 정렬하는 방법은 무엇입니까?

분류에서Dev

Javascript에서 Json 데이터를 정렬하는 방법은 무엇입니까?

분류에서Dev

PHP에서 OR 및 AND 로이 if 문을 수정하는 방법은 무엇입니까?

분류에서Dev

ActiveRecord에서 질문 및 답변 데이터 구조를 모델링하는 방법은 무엇입니까?

분류에서Dev

SQL에서 일정 기간의 데이터를 표시하도록 매개 변수를 설정하는 방법은 무엇입니까?

분류에서Dev

R의 데이터 프레임 열에서 특정 숫자를 제거하는 방법은 무엇입니까?

분류에서Dev

하나의 정렬 변수로 정렬 된 개체의 데이터 구조를 정렬하는 가장 좋은 방법은 무엇입니까?

분류에서Dev

SAS 데이터 세트 정렬 순서를 효율적으로 제거하는 방법은 무엇입니까?

분류에서Dev

zf2에서 문서의 데이터를 index.phtml로 표시하는 방법은 무엇입니까?

분류에서Dev

UITableView에서 표시 글꼴로 UIFont 제품군 및 이름을 설정하는 방법은 무엇입니까?

분류에서Dev

표시 할 새 데이터를 정렬하는 방법은 무엇입니까?

분류에서Dev

SwiftUI 및 MVVM : Firebase / Firestore의 데이터를 View에 표시하는 방법은 무엇입니까?

분류에서Dev

(<*>) 및 순수 측면에서 (*>), (<*)를 정의하는 방법은 무엇입니까?

분류에서Dev

KHelpCenter에서 ScrollKeeper 데이터베이스의 정보 페이지, 맨 페이지 및 정보를 표시하고 전체 텍스트 검색을 수행하는 방법은 무엇입니까?

분류에서Dev

룸 데이터베이스에서 LiveData를 정렬하는 방법은 무엇입니까? recyclerview의 항목 순서를 전환하는 버튼 수행

분류에서Dev

터미널에서 .log 파일의 특정 줄 수를 표시하는 방법은 무엇입니까?

분류에서Dev

Firebase 데이터베이스에서 특정 데이터를 삭제하는 방법은 무엇입니까?

분류에서Dev

이 "각괄호 구문 분석 및 균형 조정"문제를 해결하는 방법은 무엇입니까? (자바 스크립트)

분류에서Dev

이 json 구조의 날짜에서 시간 정보를 제거하는 방법은 무엇입니까?

분류에서Dev

Android에서 특정 JSON 데이터를 구문 분석하는 방법은 무엇입니까?

분류에서Dev

mongodb의 문서에서 배열 필드의 특정 데이터를 얻는 방법은 무엇입니까?

Related 관련 기사

  1. 1

    데이터 테이블 열에서 정렬 문제 날짜를 수정하는 방법은 무엇입니까?

  2. 2

    파일의 '문자열'에서 표시되는 데이터를 제거하는 방법은 무엇입니까?

  3. 3

    Android에서 RecycleView의 데이터를 정렬하는 방법은 무엇입니까?

  4. 4

    내 데이터를 재정렬하는 방법은 무엇입니까? 분할 및 조옮김

  5. 5

    초기 데이터에 대해 정렬 화살표를 표시하는 방법은 무엇입니까?

  6. 6

    게시물에 사용자 정의 필드 데이터를 표시하는 방법은 무엇입니까?

  7. 7

    C #의 HtmlTable에서 데이터를 추출하고 행으로 정렬하는 방법은 무엇입니까?

  8. 8

    반응에서 어레이의 제품 정보를 표시하는 방법은 무엇입니까?

  9. 9

    Spring JPA에서 데이터를 정렬하는 방법은 무엇입니까?

  10. 10

    Javascript에서 Json 데이터를 정렬하는 방법은 무엇입니까?

  11. 11

    PHP에서 OR 및 AND 로이 if 문을 수정하는 방법은 무엇입니까?

  12. 12

    ActiveRecord에서 질문 및 답변 데이터 구조를 모델링하는 방법은 무엇입니까?

  13. 13

    SQL에서 일정 기간의 데이터를 표시하도록 매개 변수를 설정하는 방법은 무엇입니까?

  14. 14

    R의 데이터 프레임 열에서 특정 숫자를 제거하는 방법은 무엇입니까?

  15. 15

    하나의 정렬 변수로 정렬 된 개체의 데이터 구조를 정렬하는 가장 좋은 방법은 무엇입니까?

  16. 16

    SAS 데이터 세트 정렬 순서를 효율적으로 제거하는 방법은 무엇입니까?

  17. 17

    zf2에서 문서의 데이터를 index.phtml로 표시하는 방법은 무엇입니까?

  18. 18

    UITableView에서 표시 글꼴로 UIFont 제품군 및 이름을 설정하는 방법은 무엇입니까?

  19. 19

    표시 할 새 데이터를 정렬하는 방법은 무엇입니까?

  20. 20

    SwiftUI 및 MVVM : Firebase / Firestore의 데이터를 View에 표시하는 방법은 무엇입니까?

  21. 21

    (<*>) 및 순수 측면에서 (*>), (<*)를 정의하는 방법은 무엇입니까?

  22. 22

    KHelpCenter에서 ScrollKeeper 데이터베이스의 정보 페이지, 맨 페이지 및 정보를 표시하고 전체 텍스트 검색을 수행하는 방법은 무엇입니까?

  23. 23

    룸 데이터베이스에서 LiveData를 정렬하는 방법은 무엇입니까? recyclerview의 항목 순서를 전환하는 버튼 수행

  24. 24

    터미널에서 .log 파일의 특정 줄 수를 표시하는 방법은 무엇입니까?

  25. 25

    Firebase 데이터베이스에서 특정 데이터를 삭제하는 방법은 무엇입니까?

  26. 26

    이 "각괄호 구문 분석 및 균형 조정"문제를 해결하는 방법은 무엇입니까? (자바 스크립트)

  27. 27

    이 json 구조의 날짜에서 시간 정보를 제거하는 방법은 무엇입니까?

  28. 28

    Android에서 특정 JSON 데이터를 구문 분석하는 방법은 무엇입니까?

  29. 29

    mongodb의 문서에서 배열 필드의 특정 데이터를 얻는 방법은 무엇입니까?

뜨겁다태그

보관