【问题标题】:Android Notification Area CustomizationAndroid 通知区域自定义
【发布时间】:2012-09-10 07:38:50
【问题描述】:

我不知道这个问题是否会被扣分,但我到处搜索,最后的手段是stackoverflow。

我需要在通知区域横向添加五个按钮。我需要添加甚至监听器的每个按钮。我知道可以使用 RemoteViews。但我从未见过有人为每个元素添加事件监听器。

如果有人需要参考,这些是参考。

Notifications Documentation

How to create a custom notification on android

SlidingDrawer API

【问题讨论】:

    标签: java android notifications push-notification


    【解决方案1】:

    您可以添加 5 个匿名侦听器,或单个命名侦听器。

    匿名:

    Button b1 = new Button(...);
    b1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // first listener's code goes here
        }
    });
    
    Button b2 = new Button(...);
    b2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // second listener's code goes here
        }
    });
    ...
    

    named 大致相同,但包含一个 switch 语句来区分发生的情况:

    View.OnClickListener myListener = new View.OnClickListener() {
        public void onClick(View v) {
            String buttonTitle = ((Button)v).getText();
            if ("title1".equals(buttonTitle)) {
                // do things for the first button's click
            } else if ("title2".equals(buttonTitle)) {
                // do things for the second button's click
            }
            ...
        }
    });
    ...
    

    【讨论】:

      猜你喜欢
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多