2013-11-14 28 views
0

沒有項目我有一個問題,同時顯示索尼的SmartWatch 2在列表控件

列表,我複製從樣本項目(AdvancedControlSample)的佈局和我有下面的類:

public class OpenPositionsView extends ControlExtension implements BaseView { 
    private static final String LOG_TAG = "TAGG"; 

    private Context context; 
    private ControlViewGroup mLayout; 

    public OpenPositionsView(Context context, String hostAppPackageName) { 
     super(context, hostAppPackageName); 
     this.context = context; 
     mLayout = setup(); 
    } 

    public ControlViewGroup setup() { 
     Log.i(LOG_TAG, "setup"); 

     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.watch_positions, null); 
     ControlViewGroup mLayout = (ControlViewGroup) parseLayout(layout); 

     return mLayout; 
    } 

    public void show(Controller parent) { 

     int listCount = DataProvider.getInstance().getPositions().size(); 
     parent.sendListCountM(R.id.watch_positions_listview, listCount); 
     parent.sendListPositionM(R.id.watch_positions_listview, 0); 
     parent.refreshLayout(R.layout.watch_positions, null); 


     Log.i(LOG_TAG, "show [listCount: " + listCount + "]"); 
    } 

    @Override 
    public void onRequestListItem(final int layoutReference, final int listItemPosition) { 
     Log.d(LOG_TAG, "onRequestListItem [layoutReference: " + layoutReference + ", position: " + listItemPosition + "]"); 
     if (layoutReference != -1 && listItemPosition != -1 && layoutReference == R.id.watch_positions_listview) { 
      ControlListItem item = createControlListItem(listItemPosition); 
      if (item != null) { 
       Log.d(LOG_TAG, "Sending list item"); 
       sendListItem(item); 
      } 
     } 
    } 

    @Override 
    public void onListItemSelected(ControlListItem listItem) { 
     super.onListItemSelected(listItem); 
    } 

    @Override 
    public void onListItemClick(final ControlListItem listItem, final int clickType, final int itemLayoutReference) { 
     Log.d(LOG_TAG, "onListItemClick [listItemPosition: " + listItem.listItemPosition + ", clickType: " + clickType + ", itemLayoutReference: " 
       + itemLayoutReference + "]"); 
    } 

    public void onClick(int id) { 
     mLayout.onClick(id); 
    } 

    protected ControlListItem createControlListItem(int position) { 
     Log.d(LOG_TAG, "createControlListItem [position: " + position + "]"); 

     ControlListItem item = new ControlListItem(); 
     item.layoutReference = R.id.watch_positions_listview; 
     item.dataXmlLayout = R.layout.watch_positions_item; 
     item.listItemPosition = position; 

     // We use position as listItemId. Here we could use some other unique id 
     // to reference the list data 
     item.listItemId = position; 

     Position target = DataProvider.getInstance().getPosition(position); 

     if (target != null) { 
      Bundle symbolBundle = new Bundle(); 
      symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol); 
      symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol()); 

      Bundle typeBundle = new Bundle(); 
      typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type); 
      typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString()); 

      item.layoutData = new Bundle[2]; 
      item.layoutData[0] = symbolBundle; 
      item.layoutData[1] = typeBundle; 
      Log.d(LOG_TAG, "Item list created: [symbolBundle: " + symbolBundle + ", typeBundle: " + typeBundle + "]"); 
     } 

     return item; 
    } 

    protected Bundle[] createBundle(int position) { 
     Bundle[] result = new Bundle[2]; 

     Position target = DataProvider.getInstance().getPosition(position); 

     if (target != null) { 
      Bundle symbolBundle = new Bundle(); 
      symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol); 
      symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol()); 

      Bundle typeBundle = new Bundle(); 
      typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type); 
      typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString()); 

      result[0] = symbolBundle; 
      result[1] = typeBundle; 
     } 
     return result; 
    } 
} 

然而,onRequestListItem被調用並且createControlListItem返回正確的項目列表。觸摸顯示器給我以下結果:

onListItemClick [listItem: com.sony[email protected]423b6960, clickType: 0, itemLayoutReference: -1] 

的問題是,我沒有看到任何「添加」列表項:(

回答

1

確保還從清單中複製的列表相關的意圖.XML:

<action android:name="com.sonyericsson.extras.aef.control.LIST_REFERESH_REQUEST" /> 
<action android:name="com.sonyericsson.extras.aef.control.LIST_REQUEST_ITEM" /> 
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_CLICK" /> 
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_SELECTED" /> 
0

你對夫婦的問題:??

  1. 什麼正在屏幕上顯示的是它只是空白
  2. 你在調用showLayout()和sendListCount()嗎?我沒有看到他們在上面的代碼。在onResume()中的示例代碼中,您應該看到如下內容:

    showLayout(R.layout.layout_test_list,null); sendListCount(R.id.listView,mListContent.length);

    這些需要被調用。

  3. 您是否確定sendListItem(item)實際上被調用?

+0

廣告。 1.它不是空白的,它像例子一樣顯示頂部欄,但是沒有元素在列表中可見。 廣告。 2和3.是的,我打電話給他們。我在調試器中驗證了它。 我甚至注意到我無法從樣本中更改數據包名稱。將com.sonymobile.smartconnect.extension.advancedcontrolsample更改爲com.myapp後,應用程序會編譯,但當我點擊手錶上的圖標時,什麼都不會發生。當然,我也用明顯的方式改變了它。 – oskario

0

是不是將黑色文本項目添加到黑色背景佈局? :)請檢查您的佈局。