activity-main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginTop="8dp" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/addLL" android:orientation="horizontal" > <EditText android:id="@+id/nameET" android:layout_weight="1" android:hint="商品名称" android:inputType="textPersonName" android:layout_width="0dp" android:layout_height="wrap_content" /> <EditText android:id="@+id/balanceET" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="商品金额" android:inputType="number" /> <ImageView android:onClick="add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/addIV" android:src="@android:mipmap/sym_def_app_icon" /> </LinearLayout> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/accountLV" ></ListView> </LinearLayout>
item.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="horizontal" android:padding="10dp" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/idTV" android