1.主界面布局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" >    <TextView  android:layout_width="match_parent" android:layout_height="50dp" android:background="#339933" android:gravity="center" android:text="配置设备" android:textColor="#ffffff" android:textSize="20dp" />    <ListView  android:id="@+id/smart_control_lamp_listview" android:layout_width="match_parent" android:layout_height="match_parent" >    </ListView></LinearLayout>
2.SceneMatchSwitchActivity界面代码
public class SceneMatchSwitchActivity extends Activity {    private ListView    mLampListview;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 加载布局        setContentView(R.layout.activity_scene_match_switches);        mLampListview = (ListView) findViewById(R.id.smart_control_lamp_listview);        // listview绑定Adapter        mLampListview.setAdapter(new myAdapter());        // 获取服务器反馈回来的设备类型    }    private class myAdapter extends BaseAdapter {        @Override        public int getCount() {            // 返回listview的item的总数            return 7;        }        @Override        public Object getItem(int position) {            return null;        }        @Override        public long getItemId(int position) {            return 0;        }        @Override        public View getView(int position, View convertView, ViewGroup parent) {            ViewHolder holder = null;            if (convertView == null) {                // 通过布局创建listview的item                convertView = View.inflate(getApplicationContext(), R.layout.item_bluetooth_device_status, null);                holder = new ViewHolder();                convertView.setTag(holder);                // 给holder找view                holder.mTextViewDeviceName = (TextView) convertView.findViewById(R.id.bluetooth_device_name_textview);                holder.mTextViewDeviceState = (TextView) convertView.findViewById(R.id.bluetooth_device_state);                holder.mTextViewDeviceSwitch = (ImageView) convertView.findViewById(R.id.bluetooth_device_switch_imageview);                holder.mTextViewDeviceIcon = (ImageView) convertView.findViewById(R.id.bluetooth_device_icon_imageview);            } else {                holder = (ViewHolder) convertView.getTag();            }            // 给控件设置数据            // mTextViewPosition.setText("位置 " + position);            // mTextViewName.setText("姓名 " + position);            return convertView;        }        // holder把item的控件变量集合起来,避免每次加载都再找一次id        private class ViewHolder {            TextView    mTextViewDeviceName;    // 设备名字            TextView    mTextViewDeviceState;   // 设备状态            ImageView   mTextViewDeviceSwitch;  // 设备打开或者关闭            ImageView   mTextViewDeviceIcon;    // 设备图片        }    }}
3.listview要加载的item样式:图片以及布局代码

  • 布局代码:
<?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" android:layout_weight="1" android:padding="5dp" >    <ImageView  android:id="@+id/bluetooth_device_switch_imageview" style="@style/HotelModeSelect_001" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="30dp" android:src="@drawable/openguan" />    <ImageView  android:id="@+id/bluetooth_device_icon_imageview" style="@style/HotelModeSelect_001" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="9dp" android:src="@drawable/lock_close_icon" />    <LinearLayout  style="@style/HotelModeSelect_001" android:layout_centerVertical="true" android:layout_marginLeft="16dp" android:layout_toRightOf="@+id/bluetooth_device_icon_imageview" android:orientation="vertical" >        <TextView  android:id="@+id/bluetooth_device_name_textview" style="@style/HotelModeSelect_001" android:textColor="#000000" android:text="门锁" />        <LinearLayout  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="3dp" >            <TextView  style="@style/HotelModeSelect_001" android:text="状态:" android:textColor="#66000000" android:textSize="10sp" />            <TextView  android:id="@+id/bluetooth_device_state" style="@style/HotelModeSelect_001" android:text="未上锁" android:textColor="#66000000" android:textSize="10sp" />        </LinearLayout>    </LinearLayout></RelativeLayout>

更多相关文章

  1. 一个Android实现图片的倒影效果的代码示例
  2. 安卓(Android)九宫格布局介绍
  3. 判断android设备是否支持多点触控
  4. Android O 设备不允许安装第三方APP
  5. android获取设备屏幕分辨率的方法
  6. Jquery 判断是否 移动设备 浏览
  7. 访问android所有可以使用的外接设备

随机推荐

  1. 增强的for循环中局部变量的范围
  2. javaScript函数中执行C#代码中的函数
  3. thinking in java逍遥游记 之 夜的第四章
  4. Maven编译提示:软件包不存在
  5. java 使用jdbc连接Greenplum数据库和Post
  6. ********** javamaill邮箱发送问题 *****
  7. Java对象引用处理机制
  8. java数组和c中数组的区别
  9. 北京一年工作经验的java web开发程序员税
  10. 雪天,荆棘丛中,跪求,帮帮忙。