我有一个发布一对实时卡片的 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;
}
}