标签:
Java类:
1 package com.example.dbwater.myapplication; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.ViewGroup; 7 import android.widget.BaseAdapter; 8 import android.widget.ListView; 9 import android.widget.SimpleAdapter; 10 11 import java.util.ArrayList; 12 import java.util.HashMap; 13 import java.util.List; 14 import java.util.Map; 15 16 public class MainActivity extends AppCompatActivity { 17 18 ListView lv_1; 19 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 setContentView(R.layout.activity_main); 24 lv_1=(ListView)findViewById(R.id.lv_1); 25 Myadapter myadapter=new Myadapter(); 26 lv_1.setAdapter(myadapter); 27 28 } 29 class Myadapter extends BaseAdapter{ 30 @Override 31 public int getCount() { 32 return 2; 33 } 34 35 @Override 36 public Object getItem(int position) { 37 return position; 38 } 39 40 @Override 41 public long getItemId(int position) { 42 return position; 43 } 44 45 @Override 46 public View getView(int position, View convertView, ViewGroup parent) { 47 if (convertView==null) 48 { 49 convertView=View.inflate(MainActivity.this,R.layout.listviewitem,null); 50 } 51 return convertView; 52 } 53 } 54 55 }
Listview主界面layout代码:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:background="#ffffff" 8 android:orientation="vertical" 9 tools:context="com.example.dbwater.myapplication.MainActivity"> 10 11 <FrameLayout 12 android:layout_width="match_parent" 13 android:layout_height="56dp" 14 android:background="#f81"> 15 16 <ImageButton 17 android:layout_width="wrap_content" 18 android:layout_height="match_parent" 19 android:id="@+id/backMain" 20 android:onClick="finshClick" 21 android:background="@drawable/back"/> 22 <TextView 23 android:layout_width="wrap_content" 24 android:layout_height="match_parent" 25 android:layout_gravity="center" 26 android:gravity="center_vertical" 27 android:text="购物车"/> 28 </FrameLayout> 29 <LinearLayout 30 android:layout_width="match_parent" 31 android:layout_height="0dp" 32 android:layout_weight="0.9"> 33 <ListView 34 android:layout_width="match_parent" 35 android:layout_height="match_parent" 36 android:id="@+id/lv_1"> 37 38 </ListView> 39 </LinearLayout> 40 <LinearLayout 41 android:layout_width="match_parent" 42 android:layout_height="0dp" 43 android:layout_weight="0.1" 44 android:orientation="horizontal"> 45 <RadioButton 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:layout_gravity="center_vertical"/> 49 <TextView 50 android:layout_width="0dp" 51 android:layout_height="match_parent" 52 android:layout_weight="1" 53 android:text="全选" 54 android:gravity="center_vertical" 55 android:textSize="20dp"/> 56 <TextView 57 android:layout_width="0dp" 58 android:layout_height="match_parent" 59 android:layout_weight="1" 60 android:gravity="center_vertical" 61 android:text="合计:0.00" 62 android:textSize="20dp"/> 63 <Button 64 android:layout_width="0dp" 65 android:layout_height="match_parent" 66 android:layout_weight="1" 67 android:background="#f81" 68 android:text="结算" 69 android:textSize="20dp" 70 android:textColor="#fff" 71 android:gravity="center_horizontal|center_vertical" /> 72 </LinearLayout> 73 </LinearLayout>
Listview列表项layout代码:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="horizontal" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <RadioButton 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:layout_gravity="center_vertical" 10 android:id="@+id/rb_1"/> 11 <ImageView 12 android:layout_width="0dp" 13 android:layout_weight="1" 14 android:layout_height="100dp" 15 android:background="@drawable/i2" 16 android:layout_gravity="center_vertical" 17 android:id="@+id/iv_2"/> 18 <LinearLayout 19 android:layout_width="160dp" 20 android:layout_height="100dp" 21 android:layout_gravity="center_vertical" 22 android:orientation="vertical"> 23 <TextView 24 android:layout_width="match_parent" 25 android:layout_height="0dp" 26 android:layout_weight="0.3" 27 android:id="@+id/tv_1" 28 android:text="柳橙莲子套装" 29 android:textSize="20dp" 30 /> 31 <TextView 32 android:layout_width="match_parent" 33 android:layout_height="0dp" 34 android:layout_weight="0.2" 35 android:text="内含柳橙5个,莲子2公斤" 36 android:id="@+id/tv_2"/> 37 <TextView 38 android:layout_width="match_parent" 39 android:layout_height="0dp" 40 android:layout_weight="0.5" 41 android:text="¥30.9" 42 android:textSize="30dp" 43 android:textColor="#f81" 44 android:id="@+id/tv_3"/> 45 </LinearLayout> 46 <LinearLayout 47 android:layout_width="0dp" 48 android:layout_weight="1" 49 android:layout_height="wrap_content" 50 android:orientation="vertical" 51 android:layout_gravity="center_vertical"> 52 <LinearLayout 53 android:layout_width="150dp" 54 android:layout_height="0dp" 55 android:layout_weight="1" 56 android:orientation="horizontal" 57 android:layout_gravity="center"> 58 <ImageButton 59 android:layout_width="0dp" 60 android:layout_weight="1" 61 android:layout_height="match_parent" 62 android:background="@drawable/jian" 63 android:id="@+id/ib_2"/> 64 <ImageButton 65 android:layout_width="0dp" 66 android:layout_weight="1" 67 android:layout_height="match_parent" 68 android:background="@drawable/shuliang" 69 android:id="@+id/ib_3"/> 70 <ImageButton 71 android:layout_width="0dp" 72 android:layout_weight="1" 73 android:layout_height="match_parent" 74 android:background="@drawable/jia" 75 android:id="@+id/ib_4"/> 76 </LinearLayout> 77 <LinearLayout 78 android:layout_width="match_parent" 79 android:layout_height="0dp" 80 android:layout_weight="1" 81 android:gravity="right"> 82 <ImageButton 83 android:layout_width="wrap_content" 84 android:layout_height="match_parent" 85 android:background="@drawable/shanchu" 86 android:layout_gravity="bottom" 87 android:layout_marginRight="20dp" 88 android:id="@+id/ib_5"/> 89 </LinearLayout> 90 </LinearLayout> 91 </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/beens/p/5753172.html