效果:
布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg_environment" tools:context=".QueryShopping"> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" android:layout_marginTop="20dp" android:src="@drawable/btn_inventory_select" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignTop="@id/imageView1" android:layout_marginBottom="20dp" android:layout_marginRight="20dp" android:layout_toRightOf="@id/imageView1" android:background="@drawable/bg_frame_descend_setting" android:gravity="center_horizontal" android:orientation="vertical" android:padding="10dip" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="订单号:" android:textColor="@color/white" /> <EditText android:id="@+id/editText1" android:layout_width="80dp" android:layout_height="24dip" android:background="@drawable/input" android:padding="2dp" android:singleLine="false" android:textColor="@color/white" > <requestFocus /> </EditText> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="起始时间:" android:textColor="#ffffff" /> <Button android:id="@+id/btnStartTime" android:layout_width="100dip" android:layout_height="24dip" android:background="@drawable/input" android:gravity="center" android:text="2015-08-01" android:textColor="#ffffff" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="结束时间:" android:textColor="#ffffff" /> <Button android:id="@+id/btnEndTime" android:layout_width="100dip" android:layout_height="24dip" android:background="@drawable/input" android:gravity="center" android:text="2015-08-14" android:textColor="#ffffff" /> <Button android:id="@+id/btnSearch" android:layout_width="142dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/btn_search" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:layout_marginTop="20dp" android:background="@drawable/input" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:id="@+id/tvNo" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="订单号" android:textColor="@color/white" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvAmount" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="金额" android:textColor="@color/white" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvState" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="状态" android:textColor="@color/white" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvTime" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="添加时间" android:textColor="@color/white" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvOperate" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="操作" android:textColor="@color/white" /> </LinearLayout> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:cacheColorHint="#00000000" android:fadingEdgeLength="0dp" > </ListView> </LinearLayout> </RelativeLayout>
引用布局:items.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="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:gravity="center_vertical" android:background="@drawable/input" android:orientation="horizontal" > <TextView android:id="@+id/tvNo" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:textColor="@color/white" android:text="订单号" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvAmount" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@color/white" android:text="金额" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvState" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="@color/white" android:text="状态" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvTime" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:textColor="@color/white" android:text="添加时间" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#ffffff" /> <TextView android:id="@+id/tvOperate" android:layout_width="0.0dp" android:layout_height="wrap_content" android:layout_weight="2" android:textColor="@color/white" android:text="操作" /> </LinearLayout> </LinearLayout>
Java类进行列表项内容的添加
import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public abstract class MyAdapter extends BaseAdapter { private Context context; public MyAdapter(Context context){ this.context = context; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHoller v; if(convertView==null){ v = new ViewHoller(); convertView = LayoutInflater.from(context).inflate(R.layout.items, null); v.mTvNo = (TextView) convertView.findViewById(R.id.tvNo); v.mTvAmount = (TextView) convertView.findViewById(R.id.tvAmount); v.mTvState = (TextView)convertView.findViewById(R.id.tvState); v.mTvTime = (TextView)convertView.findViewById(R.id.tvTime); v.mTvOperate = (TextView)convertView.findViewById(R.id.tvOperate); convertView.setTag(v); }else{ v = (ViewHoller) convertView.getTag(); } v.mTvNo.setText("201508281043"); v.mTvAmount.setText("168"); v.mTvState.setText("已发货"); v.mTvTime.setText("2015-08-28 10:43"); v.mTvOperate.setText(""); return convertView; } class ViewHoller{ TextView mTvNo,mTvAmount,mTvState,mTvTime,mTvOperate; } }
加载列表项
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ListView; public class QueryShopping extends AppCompatActivity { private ListView mlistView; private MyAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_query_shopping); mlistView = (ListView)findViewById(R.id.listView1); } }