zoukankan      html  css  js  c++  java
  • Android新手之旅(3) 信息的输出

      不管什么语言,了解信息的输出可谓紧要的事情,如vb的msgbox,js的alert,c#的MessageBox.Show,这个对于调试意义重大。Android的输出方法有:

    一、用Log输出。共分Log.v,Log.d,Log.i,Log.w,Log.e,和Log4Net差不多了,用颜色区分,在LogCat窗口中查看。

    二、用AlertDialog。将弹出窗口,并可以处理返回事件

    import android.app.AlertDialog;
    import android.content.DialogInterface;

                new AlertDialog.Builder(login.this)
                .setTitle("这是提示!")
                .setMessage("这是提示的内容")
                .setPositiveButton("关闭",new DialogInterface.OnClickListener(){public void onClick(DialogInterface di, int ii){}})
                .show();

    三、在信息栏显示。用Toast.makeText命令。

    Toast.makeText(this,"test info",Toast.LENGTH_SHORT).show();

    四、在状态栏显示。因为涉及到单击后进入另外一个Activity,所以工作量较多。

    假设已经存在一个新的Acivity名为newact,参见

    NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = new Notification(R.drawable.icon, "Hello,there!", System.currentTimeMillis());             
    n.flags = Notification.FLAG_AUTO_CANCEL;
    Intent i=new Intent();
    i.setClass(add2.this, newact.class);
    PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0);
    n.setLatestEventInfo(this, "button1", "button1的通知", pi);
    nm.notify(R.string.app_name, n);

    关于通知的更详细的设置参见

  • 相关阅读:
    run C source file like a script
    shared_ptr注意点
    C++ #if #endif #define #ifdef #ifndef #if defined #if !defined详解 (转)
    linux切换g++
    std::forward_list
    有关typename
    win7下 mysql安装(mysql-5.7.18-winx64.zip)
    c++ 库函数返回的字符串指针是否需要手动释放
    c++ const char *[] or char [][]
    校园资源助手
  • 原文地址:https://www.cnblogs.com/jetz/p/2102755.html
Copyright © 2011-2022 走看看