I want to show several ListView views, each with its corresponding title in a LinearLayout.
I have a LinearLayout, I inflate a view to fill the title and ListView and add that view to the LinearLayout in a loop, but only one title and list appears (the first one).
I want the the view containing the title and the list view, to appear as many times as the for loop repeats.
Let me show you the code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//fragment_history: a layout with a LinearLayout inside called "main"
View fragmentHistory = inflater.inflate(R.layout.fragment_history, container, false);
//I want to show a date, and all the transactions accomplished that date. With this two arrays, I pretend to loop by day, show the date as title and show the transactions of that day in the listview.
allExpenses = dataExpenses.getAllExpenses();
allDatesExpenses = dataExpenses.getAllDates();
// The LinearLayout inside the fragmentHistory layout
LinearLayout mainLayout = (LinearLayout) fragmentHistory.findViewById(R.id.main);
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// I made a for loop, and I have two different dates. Two transactions in the first date, and one in the second day. But only the two transactions are been shown.
for(int x = 0, y = allDatesExpenses.size(); x < y; x++){
View view = layoutInflater.inflate(R.layout.layout_title, null);
Expense expense = allDatesExpenses.get(x);
TextView text = Font.useHandelGotic(this.context, (TextView) view.findViewById(R.id.textViewTitleDate)) ;
text.setText(expense.getDateExpense());
ListView listview = (ListView) view.findViewById(android.R.id.list);
ArrayList<Expense> expensesByDate = (ArrayList<Expense>) dataExpenses.getExpensesByDate(expense.getDateExpense());
listview.setDivider(null);
listview.setAdapter(new AdapterTransaction(this.context, expensesByDate));
mainLayout.addView(view);
}
return fragmentHistory;
}
From the information you've given, I would guess that your LinearLayout is set to horizontal (the default), so all of your titles/listviews are actually being added but you can't see them because they're off the side. Fix that by adding
android:orientation="vertical"
to your LinearLayout XML tag.
If that's not the problem, then post the pertinent XML layouts please.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With