3

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

单击小部件后,我会出现一个自定义对话框:

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();
    }

}

单击时,我想实施https://stackoverflow.com/a/4281243/805031解决方案TextView text。我尝试了各种安排,包括:

在一个单独的文件中使用https://stackoverflow.com/a/4281243/805031SystemClock.java然后尝试从我那里调用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);

还包括https://stackoverflow.com/a/4281243/805031解决方案在 ClockHandler 文件下public void onClick(View v) {

4

0 回答 0