Android Wear:创建列表的麻烦



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

一切编译正常,我可以通过蓝牙将应用程序安装到我的Moto 360上。然而,当我在Moto 360上打开这个应用程序时,出现了一条错误信息:"很遗憾,我的应用程序已经停止了。"我只知道如果我注释掉这一行:

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

。onCreate方法,则错误不会出现,但现在应用程序的内容是空白的。任何帮助都太好了!谢谢你。

编辑: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>

相关内容

  • 没有找到相关文章

最新更新