GDK:使用现场卡中的自定​​义布局/自定​​义静态卡布局/列表视图显示列表视图

时间:2014-03-04 19:08:10

标签: android android-listview google-glass google-gdk

主要有三个问题:

1。我试图在活动中显示我自己的布局列表视图。为此,我首先创建一组静态卡,然后使用onItemClickListener创建一个intent并启动活动。但这似乎不起作用。这里有两个活动。一个是带有静态卡的CradsScrollActivity(Working),另一个是带有我的customlayout的ListCardsScrollActivity。 CardsScrollActivity调用ListCardsScrollActivity(使用listview),但这不起作用,但是logcat说它启动了活动并显示它。这是我的CardsScrollActivity

public class CardsScrollActivity extends Activity {

    private List<Card> mCards;
    private CardScrollView mCardScrollView;
    private List<CardData> mCardsData;

    private static final String TAG = "CardScrollActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        createSomeCards();

        mCardScrollView = new CardScrollView(this);
        TestCardScrollAdapter adapter = new TestCardScrollAdapter(mCards, mCardsData, this);
        mCardScrollView.setAdapter(adapter);
        mCardScrollView.activate();




        mCardScrollView.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int pos,
                    long id) {
                Log.d(TAG, "item tapped: "+pos); //working ! 
                Intent i = new Intent(CardsScrollActivity.this, ListCardsScrollActivity.class);

                startActivity(i);
            }

        });

        setContentView(mCardScrollView);
    }




      private void createSomeCards()
      {
            mCardsData = new ArrayList<CardData>();
        mCards = new ArrayList<Card>();
        Card card;  
        card = new Card(this);
        mCardsData.add(new CardData("Welcome","Swipe To Enter"));
        mCards.add(card);  
        card = new Card(this);
            card.setImageLayout(Card.ImageLayout.FULL);
            card.addImage(R.drawable.img1);
            mCardsData.add(new CardData("Background Image","Step 1"));
            mCards.add(card);
            card = new Card(this);
            card.setImageLayout(Card.ImageLayout.LEFT);
            card.addImage(R.drawable.img1);
            card.addImage(R.drawable.img2);
            mCardsData.add(new CardData("Step 1 and Step 2","End Of Cards"));
            mCards.add(card);
      }}

正如您所看到的onClickListener工作正常,它接收到该调用,但intent部分无效。这是我的ListCardsScrollActivity

public class ListCardsScrollActivity extends Activity {



    private static final String TAG = "ListCardsScrollActivity";

    private  List<String> mList ;

    private ListView mListView;

    private TestListAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);
        populateArrayList();
        mListView = (ListView)findViewById(R.id.listView);
        mAdapter = new TestListAdapter(this,R.layout.list_element,mList);
        mListView.setAdapter(mAdapter);
    }

    private void populateArrayList()
    {
        mList = new ArrayList<String>();
        mList.add("Item 1");
        mList.add("Item 2");
        mList.add("Item 3");
        mList.add("Item 4");
        mList.add("Item 5");
        mListView = (ListView)findViewById(R.id.listView);
        mAdapter = new TestListAdapter(this,R.layout.list_element,mList);
        mListView.setAdapter(mAdapter);
    }

无论如何,我可以使用自定义布局创建自己的静态卡吗?

活卡应该一直发布到时间线管理器上还是可以在我们的玻璃器皿应用程序中?如果有人可以分享一个列表视图在现场卡中实现的例子,那就太棒了。

提前致谢。

1 个答案:

答案 0 :(得分:0)

好吧尽管因为害怕因为这种非常肮脏的方式而被拒绝投票,我想分享这个作为答案,以便任何人都可以改进它或提出更好的实施:

  1. 当我正在玩玻璃杯时,我做了belwo的事情,现在我正在以程序的方式做这整个事情以便它的动态。为了记录,我所谓的列表布局将是:

    <Button 
        android:id="@+id/btn1"
        android:text="Btn 1"
        android:background="#CD3333"
        android:focusable="true"
        android:textSize="14sp"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
     <Button 
        android:id="@+id/btn2"
        android:text="Btn 2"
        android:textStyle="bold"
        android:textSize="14sp"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
      <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
      <Button 
        android:id="@+id/btn3"
        android:text="Btn 3"
        android:textStyle="bold"
        android:textSize="14sp"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
       <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
       <Button 
        android:id="@+id/btn4"
        android:text="Btn 4"
        android:background="#CD3333"
        android:textStyle="bold"
        android:textSize="14sp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
        <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000000"/>
        <Button 
        android:id="@+id/btn5"
        android:text="Btn 5"
        android:textSize="14sp"
        android:textStyle="bold"
        android:background="#CD3333"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"/>
    

  2. 在我的活动中我会这样做:

     public class ButtonListActivity extends Activity implements View.OnFocusChangeListener {
    
            public static final String TAG = "ButtonListActivity";
    
            Button mButton1;
            Button mButton2;
            Button mButton3;
            Button mButton4;
            Button mButton5;
    
            Bundle extras;
    
            ArrayList<String> list;
    
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
    
                setContentView(R.layout.list_template);
    
                list = new ArrayList<String>();
    
    
                mButton1 = (Button)findViewById(R.id.btn1);
                mButton2 = (Button)findViewById(R.id.btn2);
                mButton3 = (Button)findViewById(R.id.btn3);
                mButton4 = (Button)findViewById(R.id.btn4);
                mButton5 = (Button)findViewById(R.id.btn5);
    
    
                extras = getIntent().getExtras();
    
                if(extras!=null)
                {
                  list = extras.getStringArrayList("list"); 
    
                }
    
                mButton1.setText(list.get(0));
                mButton2.setText(list.get(1));
                mButton3.setText(list.get(2));
                mButton4.setText(list.get(3));
                mButton5.setText(list.get(4));
    
    
                mButton5.setFocusableInTouchMode(true);
                mButton5.setOnFocusChangeListener(this);
    
                mButton4.setFocusableInTouchMode(true);
                mButton4.setOnFocusChangeListener(this);
    
                mButton3.setFocusableInTouchMode(true);
                mButton3.setOnFocusChangeListener(this);
    
                mButton2.setFocusableInTouchMode(true);
                mButton2.setOnFocusChangeListener(this);
    
                mButton1.setFocusableInTouchMode(true);
                mButton1.setOnFocusChangeListener(this);
            }
    
    
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
    
               if(v.hasFocus()) 
                v.setBackgroundColor(Color.parseColor("#0EBFE9"));
               else
                   v.setBackgroundColor(Color.parseColor("#CD3333"));
            }
        }
    

    因此,实际输出将显示为带有橙色背景的列表,并且监听器可帮助您在列表中上下进行选择。列表元素设置与我得到的意图额外。在这种情况下是字符串数组列表。所以最终产品是一个看起来像布局的列表视图。

    1. 我通过使用标准的android布局来解决这个问题,或多或少像是“沉浸式”。基线:不使用卡

    2. 这更多的是评论而不是答案,请纠正我,如果错误,活卡应该被推送到时间线经理而另一半问题,我没有看到低频率的例子使用此处提到的观点的卡片:

    3. https://developers.google.com/glass/develop/gdk/ui/live-cards