2016-10-29 4 views
0

임, 문제는사용자 정의 목록보기,보기 문제

Name 
Name 
------ 
Surname 
Surname 
----- 

로 잘못 목록을 작성 ... 그리고

을 반복하는 것이 무엇인지 내가하고 싶은 것입니다 :

Name 
Surname 
------- 

내 코드는 다음과 같습니다

protected void onResume() { 
    DBHelper db = new DBHelper(this); 
    ArrayList<String> names = new ArrayList<String>(); 

    for (int i = 0; i < db.getAllContacts().size(); i++) { 
     names.add(db.getAllContacts().get(i).getName()); 
       names.add(db.getAllContacts().get(i).getEmail()); 

    } 
     ArrayAdapter adapter = new custom_row(this, names); 
     listView_allContacts.setAdapter(adapter); 

     super.onResume(); 
    } 

무엇이 잘못 되었나요? 미리 감사드립니다!

내 custom_row 코드 :

공용 클래스 custom_row는 ArrayAdapter와 {

public custom_row(Context context, ArrayList<String> names) { 
    super(context, R.layout.custom_cell, names); 

} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater peoInf = LayoutInflater.from(getContext()); 
    View customView = peoInf.inflate(R.layout.custom_cell, parent , false); 
    String singlePeople = getItem(position); 
    TextView name_text = (TextView) customView.findViewById(R.id.name_text); 
    TextView email_text = (TextView) customView.findViewById(R.id.email_text); 

    name_text.setText(singlePeople); 
    email_text.setText(singlePeople); 
    return customView; 
} 

}

+0

시도? – Vyacheslav

+0

여기에 당신을 도울만한 세부 사항이 없습니다. 우리는'custom_row' 클래스 (행이 아니고 어댑터이고 많은 행을 표시하므로 이름을 바꾸는 것이 좋습니다)를 볼 필요가 있습니다. 그럼 우리는 또한 하나의 행의 XML 레이아웃을 볼 필요가 –

+0

귀하의 질문에 [편집]과 함께 [mcve]를 보여주십시오 –

답변

0

을 확장 당신은 두 개의 서로 다른 ArrayList에있는 이름 하나와 이메일 하나가 필요합니다.

는`custom_row` 클래스는 새로운 기능이

ArrayList<String> list; 

public custom_row(Context context, ArrayList<String> names, ArrayList<String> email) { 
    super(context, R.layout.custom_cell, names); 
    list = email; 

} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater peoInf = LayoutInflater.from(getContext()); 
    View customView = peoInf.inflate(R.layout.custom_cell, parent , false); 
    String singlePeople = getItem(position); 
    String email = list.get(position); 
    TextView name_text = (TextView) customView.findViewById(R.id.name_text); 
    TextView email_text = (TextView) customView.findViewById(R.id.email_text); 

    name_text.setText(singlePeople); 
    email_text.setText(email); 
    return customView; 
} 
+0

대단히 감사합니다! 도움이됩니다! – Rufat

+0

그러면 문제는 검색 상자에 이름 열만 검색하는 것입니다. 이메일 검색도 가능합니까? – Rufat

관련 문제