将PendingIntent onClick添加到自定义对话框

时间:2012-05-11 03:18:35

标签: android android-intent customdialog

我是一个复制和粘贴编码器,这可能真的很傻......

我点击了我的小部件后出现了一个自定义对话框:

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) {

下的ClockHandler文件中包含https://stackoverflow.com/a/4281243/805031解决方案

0 个答案:

没有答案