0

当我收到来自 gcm 的通知时,我需要在该对话框中发出带有事件列表的警报对话框。我通过使用自定义 toast 消息来做到这一点。但我无法在警报对话框中为列表编写单击事件. 每当我收到新的通知时,我都会调用此方法。出现警报对话框但 onclick 事件不适用于列表..

public void displayToast()
{
    LayoutInflater mInflater = LayoutInflater.from(con);
    View myView = mInflater.inflate(R.layout.statusbar, null);
    Toast toast = new Toast(con.getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    TextView tv = (TextView) myView.findViewById(R.id.notificationtype);
    ListView lv = (ListView) myView.findViewById(R.id.listView1);
    lv.setAdapter(new StatusAdapter(con, list));
    tv.setText("MESSAGES");

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
            // TODO Auto-generated method stub
            if (list.get(arg2).getType().equals("S Notification")) {
                Intent it = new Intent(con,ViewEventActivity.class);
                it.putExtra("eventid", list.get(arg2).getId());
                it.putExtra("event", "team");
                con.startActivity(it);
                //dialog.dismiss();
            }
            if (list.get(arg2).getType().equals("S R Notification")) {
                Intent it = new Intent(con,GameDetailsActivity.class);
                it.putExtra("id", list.get(arg2).getId());
                con.startActivity(it);
                //dialog.dismiss();
            }
            if (list.get(arg2).getType().equals("A Notification")) {
                Intent intent = new Intent(con,ViewItemActivity.class);
                intent.putExtra("id", "" + list.get(arg2).getId());
                con.startActivity(intent);
                //dialog.dismiss();
            }
            if (list.get(arg2).getType().equals("D Notification")) {
                Intent it = new Intent(con,PersonalDetails.class);
                it.putExtra("personId", list.get(arg2).getId());
                con.startActivity(it);
                //dialog.dismiss();
            }
            if (list.get(arg2).getType().equals("M Notification")) {
                Intent it = new Intent(con,MessageContentActivity.class);
                it.putExtra("messageid", list.get(arg2).getId());
                con.startActivity(it);
            //  dialog.dismiss();
            }
        }
    });
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setDuration(1800000);
    toast.setView(myView);
    toast.show();
}

在此处输入图像描述

4

1 回答 1

0

Toast Window 具有WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE框架设置的属性,

因此,您拥有的任何视图都无法向其发送事件。

于 2013-01-18T13:05:43.633 回答