Ich entwickle eine Schuldenmanager App, wo Sie Personen und Geldbeträge hinzufügen können, die Sie ihnen schulden oder die sie Ihnen schulden. Die Personen sollten in einem ListView und die Schulden in einem ListView innerhalb der Personeneinträge angezeigt werden. Zur Zeit füge ich zwei Personen mit jeweils zwei Schuldeneinträgen als Dummy-Daten hinzu. Beide Personen werden im äußeren ListView angezeigt, es wird jedoch jeweils nur eine Schuldposition angezeigt.ListView in ListView zeigt nur einen Eintrag
Irgendeine Idee?
Ich habe bereits einige verwandte Fragen zu diesem Thema gelesen, aber ich fand keine Lösung.
Dies sind die relevanten Dateien:
content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context="de.cheereeo.imbroke_debtmanager.MainActivity">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/personsView"
android:layout_alignParentTop="true" android:layout_alignParentStart="true"/>
</RelativeLayout>
person_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_marginLeft="5dp"
android:id="@+id/relativeLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:id="@+id/amountView" android:layout_gravity="right"
android:layout_marginRight="5dp" android:layout_alignParentTop="true"
android:textStyle="bold" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="from"
android:id="@+id/forView" android:layout_marginRight="5dp"
android:layout_alignParentTop="true" android:layout_toEndOf="@+id/amountView" android:textStyle="bold"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jon Doe"
android:id="@+id/nameView"
android:layout_marginRight="5dp"
android:layout_gravity="center_horizontal"
android:layout_alignBottom="@+id/forView" android:layout_toEndOf="@+id/forView"
android:textStyle="bold" android:textColor="#000000"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:id="@+id/relativeLayout">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/addButton" android:layout_alignParentRight="false"
android:src="@android:drawable/ic_input_add" android:background="#ffff"
/>
<ImageButton
android:layout_width="24dp"
android:layout_height="wrap_content"
android:id="@+id/withdrawButton" android:layout_alignParentRight="false"
android:src="@android:drawable/button_onoff_indicator_on"
android:layout_toEndOf="@+id/addButton" android:layout_alignParentEnd="false"/>
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/debtsView" android:layout_below="@+id/relativeLayout"
android:layout_alignStart="@+id/relativeLayout2" android:stackFromBottom="false"/>
</RelativeLayout>
debt_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_marginLeft="5dp"
android:id="@+id/relativeLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:id="@+id/amountView" android:layout_gravity="right"
android:layout_marginRight="5dp"
android:textStyle="bold" android:textColor="#000000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="for"
android:id="@+id/forView" android:layout_marginRight="5dp"
android:layout_alignParentTop="true" android:textStyle="bold"
android:textColor="#000000" android:layout_toEndOf="@+id/amountView"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Food"
android:id="@+id/subjectView" android:layout_marginRight="5dp" android:layout_alignParentTop="true"
android:textStyle="bold" android:textColor="#000000" android:layout_toEndOf="@+id/forView"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:id="@+id/relativeLayout">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/addButton" android:layout_alignParentRight="false"
android:src="@android:drawable/ic_menu_edit" android:background="#fff"/>
</RelativeLayout>
</RelativeLayout>
PersonAdapter.java:
@EBean
public class PersonAdapter extends BaseAdapter {
List<Person> persons;
@RootContext
Context context;
@AfterInject
void initAdapter() {
persons = new ArrayList<>();
persons.add(new Person("Jon Doe"));
persons.add(new Person("Peter Pan"));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
PersonItemView personItemView;
if (convertView == null) {
personItemView = PersonItemView_.build(context);
} else {
personItemView = (PersonItemView) convertView;
}
personItemView.bind(getItem(position));
return personItemView;
}
@Override
public int getCount() {
return persons.size();
}
@Override
public Person getItem(int position) {
return persons.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
DebtAdapter.java:
@EBean
public class DebtAdapter extends BaseAdapter {
List<Debt> debts;
Person other;
@RootContext
Context context;
@AfterInject
void initAdapter() {
debts = new ArrayList<>();
debts.add(new Debt("Pizza", 5.9, this.other, Debt.Direction.BORROWED_FROM));
debts.add(new Debt("Bus ticket", 2.3, this.other, Debt.Direction.LENT_TO));
}
public void setOther(Person other) {
this.other = other;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DebtItemView debtItemView;
if (convertView == null) {
debtItemView = DebtItemView_.build(context);
} else {
debtItemView = (DebtItemView) convertView;
}
debtItemView.bind(getItem(position));
return debtItemView;
}
@Override
public int getCount() {
return debts.size();
}
@Override
public Debt getItem(int position) {
return debts.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
PersonItemView.java:
@EViewGroup(R.layout.person_item)
public class PersonItemView extends LinearLayout {
@ViewById
TextView nameView;
@ViewById
ListView debtsView;
@Bean
DebtAdapter adapter;
public PersonItemView(Context context) {
super(context);
}
public void bind(Person person) {
adapter.setOther(person);
nameView.setText(person.name);
}
@AfterViews
public void afterViews(){
debtsView.setAdapter(adapter);
}
}
DebtItemView:
@EViewGroup(R.layout.debt_item)
public class DebtItemView extends LinearLayout {
@ViewById
TextView amountView;
@ViewById
TextView subjectView;
public DebtItemView(Context context) {
super(context);
}
public void bind(Debt debt) {
amountView.setText(String.valueOf(debt.amount));
subjectView.setText(debt.subject);
}
}