【发布时间】:2013-12-25 02:25:40
【问题描述】:
我有一个发布一对实时卡片的 Google Glass 应用程序。当我单击这些卡片时,它会将我带入 Activity 的 UI。我想做的是拦截其中一张卡片上的点击,而不是将视图更改为活动布局,我想做一些动作(导致一些后台代码运行并更新另一张实时卡片) .
我没有看到任何卡片的点击监听器。有没有办法做到这一点?
编辑::: 澄清。这是我可能想要尝试做的一个非常简单的例子。这不起作用,因为 LiveCards 不接受 clickListeners...
package com.example.exampleglasslivecardselection;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RemoteViews;
import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.TimelineManager;
public class MainActivity extends Activity {
LiveCard card1;
LiveCard card2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (card1 == null && card2 == null) {
String cardId = "card1";
TimelineManager tm = TimelineManager.from(this);
// set up card 1 and publish
card1 = tm.getLiveCard(cardId);
RemoteViews views = new RemoteViews(this.getPackageName(),
R.layout.card1_page);
Intent intent = new Intent(this, MainActivity.class);
card1.setAction(PendingIntent.getActivity(this, 0,
intent, 0));
card1.publish();
// set up card 2 and publish
card2 = tm.getLiveCard(cardId);
RemoteViews views2 = new RemoteViews(this.getPackageName(),
R.layout.card2_page);
Intent twoIntent = new Intent(this, MainActivity.class);
card2.setAction(PendingIntent.getActivity(this, 0,
intent, 0));
// set up a click listener or something...(THIS DOESN"T WORK, how would I do this?)
card2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff to card 1...
card1.setViews(someNewVewis);
// TODO Auto-generated method stub
}
}
card2.publish();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
【问题讨论】:
-
你可以在Activity启动之前写一些代码,在onCreate中,然后显示UI。你能显示一些更具体的代码吗?
-
我真的不明白你的评论在说什么 Sigrlami,直到请求代码。
-
我的意思是你的卡片会导致一些远程 UI,它是 Android SDK 的一部分,在那个远程 UI 中你可以首先运行你的代码,然后在方法 onCreate 中显示 UI。另一方面,您可以创建一些调度类(中间层),它将处理来自 Intent 的参数并制作您想要的。
-
我不想让用户从时间线上转移。我也不想强迫用户查看我的新 UI。我只是想在用户选择 card2 时更新 card1。
-
当从时间线中选择卡片时,我没有看到任何可以触发的事件或其他操作。
标签: android google-glass google-gdk