Reputation: 305
On clicking Button ADD ANOTHER as in Screenshot It will add another medication after one another. So problem is that, I am unable to display the multiple data .
How can i show it using list view any help please.
Thank you in advance
Upvotes: 1
Views: 597
Reputation: 3673
Simply ,Add data in your ArrayList which you are passing in adapter constructor. After then call adapter.notifyDataSetChanged()
.If you face problem with listview height ,then set it dynamically on button click -
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
Upvotes: 1