1

I am just now learning about how listViews work. I currently have a ListView in which each row is an image, with two TextViews to its right. The top TextView is larger and contains a name, the bottom one is smaller and contains a surname. I currently have an ArrayAdapter set up properly to populate the names. However, I can't quite figure out how to also populate the surnames, as doing the same exact thing seems to not work. My code currently looks like this. The k ListView is the one I'm trying to implement for surnames. This is obviously an incorrect approach, though. If I run that code, it will no longer show the names, but only the surnames.

ListView l;
ListView k;
String[] names = {"Andrew","Billy","Charlie","Daniel","Eric","Frank","George","Hal"};
String[] surNames = {"Ainbinder","Brenton","Chen","Donovan","Epstein","Ferris","Gallivan","Higgins"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    l = (ListView) findViewById(R.id.listView1);
    k = (ListView) findViewById(R.id.listView1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.single_row, R.id.topLine, names);
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, R.layout.single_row, R.id.secondLine, surNames);
    l.setAdapter(adapter);
    k.setAdapter(adapter2);
    l.setOnItemClickListener(this);
}
Xonal
  • 1,340
  • 4
  • 20
  • 33

1 Answers1

1

The way you are implementing is not correct. You can follow the link below for correct implementation:

Multiple TextViews in the same List Item

Community
  • 1
  • 1
Sushil
  • 8,250
  • 3
  • 39
  • 71