Android Wear: Creating Lists 麻烦

Android Wear: Creating Lists trouble

我对 Android 相当陌生,对 Android Wear 开发完全陌生。最终,我的目标是动态创建一个包含 10 个项目的列表。每个项目都有一个 Image 和一个 TextView。我正在尝试实施此处给出的示例:https://developer.android.com/training/wearables/ui/lists.html。在这个例子中我唯一改变的是 res/layout/list_item.xml 文件:ImageView 没有 src。相反,我将背景颜色设置为哈希值。我还将 TextView.textColor 更改为哈希值。

一切编译正常,我可以通过蓝牙将应用程序安装到我的 Moto 360 上。但是,当我在我的 Moto 360 上打开该应用程序时,会出现一条错误消息 "Unfortunately, myApp has stopped." 我所知道的是,如果我注释掉这一行:

listView.setAdapter(new Adapter(this, elements));

在WearActivity.onCreate方法中,然后没有出现错误,但是现在app的内容是空白的。任何帮助都会很棒!谢谢。

编辑:Logcat

I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
--------- beginning of main
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.wearable.init.InitializeGmsWearableReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/GCM     ( 1994): GcmService start Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService } com.google.android
.gms.INITIALIZE
D/AuthorizationBluetoothService( 1994): Received GmsCore event: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.auth.be
.proximity.authorization.bt.AuthorizationBluetoothService$AutoStarter }.
V/GmsCoreStatsServiceLauncher(29720): Received broadcast intent Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.common.
stats.GmsCoreStatsServiceLauncher }
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.checkin.EventLogService$Receiver
I/EventLogService(29720): Aggregate from 1437604524915 (log), 1437604524915 (data)
I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
E/StreamVibrator( 1911): Found notifications that tried to vibrate, but they never made it to the top of the stream. Not vibrating.
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.checkin.EventLogService$Receiver
I/EventLogService(29720): Aggregate from 1437606510039 (log), 1437606510039 (data)
I/GoogleURLConnFactory( 1994): Using platform SSLCertificateSocketFactory
I/GoogleURLConnFactory( 1994): Using platform SSLCertificateSocketFactory
W/Uploader( 1994): No account for auth token provided
I/art     (29720): WaitForGcToComplete blocked for 17.730ms for cause DisableMovingGc
I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/ClockworkProxy( 1911): doAccept: Create socket stream 5 for TCP connection from /192.168.167.239:54729 to /74.125.25.95:443
D/ClockworkProxy( 1911): doAccept: rpc succeeded. Activate stream 5
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
E/StreamVibrator( 1911): Found notifications that tried to vibrate, but they never made it to the top of the stream. Not vibrating.
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/SensorHAL( 1785): adjustSensorHandle: handle = 10 adjustedHandle = 1
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.checkin.EventLogService$Receiver
I/EventLogService(29720): Aggregate from 1437608311873 (log), 1437608311873 (data)
I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
I/art     ( 1785): Explicit concurrent mark sweep GC freed 31045(2046KB) AllocSpace objects, 5(80KB) LOS objects, 19% free, 7MB/9MB, paused 1.708ms total 103.118ms
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
E/StreamVibrator( 1911): Found notifications that tried to vibrate, but they never made it to the top of the stream. Not vibrating.
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.checkin.EventLogService$Receiver
I/EventLogService(29720): Aggregate from 1437610113756 (log), 1437610113756 (data)
I/GoogleURLConnFactory( 1994): Using platform SSLCertificateSocketFactory
I/ActivityManager( 1785): Resuming delayed broadcast
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
D/SensorHAL( 1785): adjustSensorHandle: handle = 10 adjustedHandle = 1
E/StreamVibrator( 1911): Found notifications that tried to vibrate, but they never made it to the top of the stream. Not vibrating.
I/ActivityManager( 1785): Delay finish: com.motorola.targetnotif/com.motorola.omni.NotificationAlarmReceiver
I/ActivityManager( 1785): Resuming delayed broadcast
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/StreamVibrator( 1911): Found notifications that tried to vibrate, but they never made it to the top of the stream. Not vibrating.
W/bt-btif ( 2231): dm_pm_timer expires
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires
E/libsuspend( 1785): Error writing to /sys/power/state: Device or resource busy
I/ActivityManager( 1785): Delay finish: com.google.android.gms/.checkin.EventLogService$Receiver
I/EventLogService(29720): Aggregate from 1437611998899 (log), 1437611998899 (data)
I/ActivityManager( 1785): Resuming delayed broadcast
W/bt-btif ( 2231): dm_pm_timer expires 0
W/bt-btif ( 2231): proc dm_pm_timer expires

根据要求,这里是编码解决方案:

<!--<?xml version="1.0" encoding="utf-8"?>-->
<com.my.app.WearableListItemLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_gravity="center_vertical"
        android:gravity="center_vertical">

        <ImageView
            android:id="@+id/ID1"
            android:layout_height="70dp"
            android:layout_margin="2dp"
            android:layout_width="70dp"
            android:adjustViewBounds="true"/>

        <TextView
            android:id="@+id/ID2"
            android:gravity="center_vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-condensed-light"
            android:textColor="#000003"
            android:textSize="12sp"
            android:layout_gravity="center_vertical"/>
            <!--android:drawableTop="@drawable/myImage"/>-->
            <!--android:drawablePadding="2dp"/>-->
    </LinearLayout>
</com.my.app.WearableListItemLayout>