布局代码如下:
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#62a653"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/ib_gsgl_add"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentRight="true"
android:layout_marginBottom="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="12dp"
android:background="@drawable/nav_add" />
<ImageButton
android:id="@+id/ib_setback"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_marginBottom="12dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:background="@drawable/nav_back" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:background="#62a653"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" >
<EditText
android:id="@+id/search_et_input"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:drawableLeft="@drawable/nav_search"
android:hint="搜"
android:imeOptions="actionSearch"
android:inputType="text"
android:textSize="12sp" />
<ImageView
android:id="@+id/search_iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="20dp"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rl_admin"
android:layout_width="match_parent"
android:layout_height="35dp" >
<ImageView
android:id="@+id/iv_admin"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_admin" />
<TextView
android:id="@+id/tv_admin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_toRightOf="@+id/iv_admin"
android:text="管"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_admin_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCCCCC" />
<ListView
android:id="@+id/lv_admin"
android:layout_width="match_parent"
android:layout_height="96dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="12dp"
android:background="#CCCCCC" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_gsgl_bmgl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:text="部"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_bmgl_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#CCCCCC" />
<RelativeLayout
android:id="@+id/rl_psb"
android:layout_width="match_parent"
android:layout_height="35dp" >
<ImageView
android:id="@+id/iv_psb"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_admin" />
<TextView
android:id="@+id/tv_psb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_toRightOf="@+id/iv_psb"
android:text="配"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_psb_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#CCCCCC" />
<!-- 这里的listview预览可以显示,手机显示不了--!>
<ListView
android:id="@+id/lv_psb"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<Button
android:id="@+id/bt_gsgl_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#62a653"
android:text="保"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
Adapter页面:
public class DepartmentAdapter extends ArrayAdapter<Department> {
private int resonurceId;
public DepartmentAdapter(Context context, int textViewResourceId,
List<Department> objects) {
super(context, textViewResourceId, objects);
resonurceId = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Department department = getItem(position);
View view = LayoutInflater.from(getContext())
.inflate(resonurceId, null);
TextView tvDepartmentName = (TextView) view
.findViewById(R.id.tv_psb_name);
TextView tvDepartmentPhone = (TextView) view
.findViewById(R.id.tv_psb_phone);
tvDepartmentName.setText(department.getDepartmentName());
tvDepartmentPhone.setText(department.getDepartmentPhone());
return view;
}
}
Activity页面:
public class CorporationManagementActivity extends Activity {
private List<GsglAdminUtil> adminList = new ArrayList<GsglAdminUtil>();
private List<Department> departmentsList = new ArrayList<Department>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_gsgl);
initAdmin();
AdminAdapter adapter = new AdminAdapter(this, R.layout.admin_item, adminList);
ListView listView = (ListView) findViewById(R.id.lv_admin);
listView.setAdapter(adapter);
initDepartment();
DepartmentAdapter departmentAdapter = new DepartmentAdapter(this, R.layout.psb_item, departmentsList);
ListView list = (ListView) findViewById(R.id.lv_psb);
list.setAdapter(departmentAdapter);
}
private void initDepartment() {
Department ze = new Department("赵", "9");
departmentsList.add(ze);
Department zs = new Department("张", "9");
departmentsList.add(zs);
}
private void initAdmin() {
GsglAdminUtil zs = new GsglAdminUtil("张", "1");
adminList.add(zs);
GsglAdminUtil ls = new GsglAdminUtil("李", "1");
adminList.add(ls);
}
}
<?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="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#62a653"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/ib_gsgl_add"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentRight="true"
android:layout_marginBottom="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="12dp"
android:background="@drawable/nav_add" />
<ImageButton
android:id="@+id/ib_setback"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:layout_alignParentLeft="true"
android:layout_marginBottom="12dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:background="@drawable/nav_back" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:background="#62a653"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" >
<EditText
android:id="@+id/search_et_input"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:drawableLeft="@drawable/nav_search"
android:hint="搜"
android:imeOptions="actionSearch"
android:inputType="text"
android:textSize="12sp" />
<ImageView
android:id="@+id/search_iv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="20dp"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rl_admin"
android:layout_width="match_parent"
android:layout_height="35dp" >
<ImageView
android:id="@+id/iv_admin"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_admin" />
<TextView
android:id="@+id/tv_admin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_toRightOf="@+id/iv_admin"
android:text="管"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_admin_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCCCCC" />
<ListView
android:id="@+id/lv_admin"
android:layout_width="match_parent"
android:layout_height="96dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="12dp"
android:background="#CCCCCC" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_gsgl_bmgl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:text="部"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_bmgl_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#CCCCCC" />
<RelativeLayout
android:id="@+id/rl_psb"
android:layout_width="match_parent"
android:layout_height="35dp" >
<ImageView
android:id="@+id/iv_psb"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_admin" />
<TextView
android:id="@+id/tv_psb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_toRightOf="@+id/iv_psb"
android:text="配"
android:textColor="#333333"
android:textSize="12sp" />
<ImageButton
android:id="@+id/ib_psb_ss"
android:layout_width="12dp"
android:layout_height="7dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/icon_down" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#CCCCCC" />
<!-- 这里的listview预览可以显示,手机显示不了--!>
<ListView
android:id="@+id/lv_psb"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<Button
android:id="@+id/bt_gsgl_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#62a653"
android:text="保"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
Adapter页面:
public class DepartmentAdapter extends ArrayAdapter<Department> {
private int resonurceId;
public DepartmentAdapter(Context context, int textViewResourceId,
List<Department> objects) {
super(context, textViewResourceId, objects);
resonurceId = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Department department = getItem(position);
View view = LayoutInflater.from(getContext())
.inflate(resonurceId, null);
TextView tvDepartmentName = (TextView) view
.findViewById(R.id.tv_psb_name);
TextView tvDepartmentPhone = (TextView) view
.findViewById(R.id.tv_psb_phone);
tvDepartmentName.setText(department.getDepartmentName());
tvDepartmentPhone.setText(department.getDepartmentPhone());
return view;
}
}
Activity页面:
public class CorporationManagementActivity extends Activity {
private List<GsglAdminUtil> adminList = new ArrayList<GsglAdminUtil>();
private List<Department> departmentsList = new ArrayList<Department>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_gsgl);
initAdmin();
AdminAdapter adapter = new AdminAdapter(this, R.layout.admin_item, adminList);
ListView listView = (ListView) findViewById(R.id.lv_admin);
listView.setAdapter(adapter);
initDepartment();
DepartmentAdapter departmentAdapter = new DepartmentAdapter(this, R.layout.psb_item, departmentsList);
ListView list = (ListView) findViewById(R.id.lv_psb);
list.setAdapter(departmentAdapter);
}
private void initDepartment() {
Department ze = new Department("赵", "9");
departmentsList.add(ze);
Department zs = new Department("张", "9");
departmentsList.add(zs);
}
private void initAdmin() {
GsglAdminUtil zs = new GsglAdminUtil("张", "1");
adminList.add(zs);
GsglAdminUtil ls = new GsglAdminUtil("李", "1");
adminList.add(ls);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货