-3

I have a ListView which has a single choice. I placed an add function for it. My code is:

public void add(){
    String name = (allergytxt.getText().toString() + "\n" +
                   desctxt.getText().toString() + "\n" +
                   doctxt.getText().toString() + "\n" +
                   notxt.getText().toString());

    if (!name.isEmpty() && name.length() > 0) {
        adapter.add(name);
        adapter.notifyDataSetChanged();
        allergytxt.setText("");
        desctxt.setText("");
        doctxt.setText("");
        notxt.setText("");
        Toast.makeText(MainActivity.this, "added",Toast.LENGTH_SHORT).show();
   }
}

Apparently the listview would only display 2 lines of text. Heeeelp. (I'm new to androdid studio and java by the way)

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

1 Answers1

-1

The best way to do this is to create a custom adapter to give you more control over the layout of each row.

By default an adapter returns a simple TextView as a row. In the event that you want a more complicated layout row for your ListView, you need a custom adapter. Seems like a tedious process at first but you'll get used to it. This Tutorial really helped me the first time I tried. Also look at this answer. Happy coding!

Community
  • 1
  • 1
Fourth
  • 630
  • 1
  • 7
  • 22