2016-10-29 6 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は、あなたが名前と電子メールのいずれかの二つの異なるArrayListのいずれかが必要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'クラス(行ではなく、アダプタであり、多くの行を表示するので、名前を変更することをお勧めします)を参照する必要があります。次に、1行のXMLレイアウトを参照する必要があります –

+0

あなたの質問に[編集]で[mcve]を表示してください –

答えて

0

を拡張します。

`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

問題は、searchBoxを追加して名前列だけを検索することです。メール検索も可能ですか? – Rufat

関連する問題