I have problem with displaying data in my listview. it’s not displaying vertically.
here’s my code:
private ListView lv;
private ArrayList<String> results = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.meal_result);
BreakFastLog info = new BreakFastLog(this);
info.open();
String data1 = info.getMealNameData();
//String data2 = info.getServingData();
results.add(data1);
lv = (ListView) findViewById (R.id.lvBF);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, results));
lv.setTextFilterEnabled(true);
info.close();
}
and my 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" >
<ListView
android:id="@+id/lvBF"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
What’s wrong with this? please help me figure out what makes it displayed horizontally.
Here’s the screenshot:

After gone through your code,
You have a only one String value
String data1 = info.getMealNameData();in your
ArrayList<String> results. And results is added to your List Adapter.So only one row displayed in your
ListView.So You have to either make a
String[]for all user Inputs instead of your oneString data1and pass thatString[]to your List Adapter.Update: