我是一个复制和粘贴编码器,这可能真的很傻......
我点击了我的小部件后出现了一个自定义对话框:
public class ClockHandler extends Activity {
final Context context = this;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.clockhandler);
dialog.setTitle("Available Clocks...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("System Clocks");
text.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Searching for System Clock...", Toast.LENGTH_SHORT).show();
// Trying to open System Clock
// referencing https://stackoverflow.com/a/4281243/805031
}
});
TextView text2 = (TextView) dialog.findViewById(R.id.text2);
text2.setText("More Clock Widgets!");
text2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Clock Widget Gallery Coming SOON!!!", Toast.LENGTH_LONG).show();
// Open clock widget gallery
// eventually
}
});
dialog.show();
}
}
我想在点击TextView text
时实施https://stackoverflow.com/a/4281243/805031解决方案。我尝试过各种各样的安排,包括:
在单独的文件SystemClock.java
中使用https://stackoverflow.com/a/4281243/805031,然后尝试使用
ClockHandler
调用该文件
final RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.clockhandler);
final PendingIntent intent = SystemClock.getClockIntent(context);
if (intent != null){
rv.setOnClickPendingIntent(R.id.text, intent);
和
Intent intent = new Intent();
PendingIntent.getActivity(context, 0, intent, 0);
并在public void onClick(View v) {