GDK:使用自定义布局/自定义静态卡片布局/列表视图中的活卡显示一个列表视图 [英] GDK: Displaying a listview using custom layout/custom static card layout/listview in live cards
问题描述
三问在这里主要是:
1。我想有一个活动在我自己的布局显示一个列表视图。对于这第一个我创建了一组静态卡,然后通过使用onItemClickListener我创建一个意图,并开始活动。但是,这似乎没有工作。这里有两个活动。一个是CradsScrollActivity(工作)与静态卡和明年是ListCardsScrollActivity我customlayout。该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工作正常,它接收呼叫,但目的一部分是行不通的。这是我的ListCardsScrollActivity
As you see the onClickListener is working fine, it receives that call, but the intent part is not working. Here is my 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);
}
反正我有可以自定义布局创建自己的静态卡?
应该是一直到公布的时间线经理现场卡还是可以在我们的玻璃器皿应用程序?这将是巨大的,如果任何人都可以共享,其中一个ListView在现场卡实现的一个例子。
在此先感谢。
推荐答案
尽管对被下投票支持这真的肮脏的方式恐惧好吧,我想和大家分享这其中的答案,使任何人都可以改善,或拿出更多更好的实现:
Ok despite for the fear of being down voted for this really dirty way, I would like to share this one as answer, so that anyone could improve on it or come up with a lot more better implementation:
-
由于我只是在摆弄玻璃,我做了belwo的事情,现在我正在做这整个东西programtically 因此多数民众赞成它的动态。为了记录在案,我所谓的列表布局将是:
As I am just playing around with the glass, I did the belwo thing, now I am doing this whole stuff programtically so thats Its dynamic . For the record, my so called list layout would be:
<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"/>
和我的活动我会做这样的:
and in my Activity I would do this:
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"));
}
}
所以实际输出将显示为橙色背景列表,听者会帮助你让你的选择,你去向上和向下的列表。该列表中的元素设置的意图演员我得到。在这种情况下,一个字符串数组列表。因此,最终产品是一个ListView看起来像布局。
So the actual output would appear as a list with orange background and the listener would help you make your selection as you go up and down your list. The list elements are set with the intent extras I am getting. In this case a string array list. So the final produce is a listview looking like layout.
我通过使用标准的Android布局,或多或少像一个浸泡式解决了这一点。基线:不使用卡
I resolved this by using the standard android layouts, more or less like an "immersion". Baseline: Not using cards
这是多评论不是一个答案,请纠正我,如果错了,活卡都应该被推向时间表经理和另一半的问题,我没有看到一个低频现场的一个例子使用这里提到一个观点卡:
This is more of a comment than an answer, please correct me if wrong, live cards are supposed to be pushed to timeline manager and for the other half question, I did not see an example of a low frequency live cards using a the views mentioned here:
https://developers.google.com/glass/develop/ GDK / UI /活卡
这篇关于GDK:使用自定义布局/自定义静态卡片布局/列表视图中的活卡显示一个列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!