布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Button        android:id="@+id/updateBtn"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="Update ProcessInfos" />    <TextView        android:id="@+id/time"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:textSize="16sp"        android:textStyle="bold" />    <ScrollView        android:layout_width="match_parent"        android:layout_height="match_parent" >        <TextView            android:id="@+id/text"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="16sp"             android:padding="5dp"/>    </ScrollView></LinearLayout>

Code

public class HelloProcessActivity extends Activity{    private TextView mTextView = null;    private TextView mTime = null;    private Button mButton = null;    private String mText = "";    @Override    protected void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_hello_process);        mTextView = (TextView) findViewById(R.id.text);        mTime = (TextView) findViewById(R.id.time);        mButton = (Button) findViewById(R.id.updateBtn);        mButton.setOnClickListener(new View.OnClickListener()        {            @Override            public void onClick(View v)            {                updateProcessInfo();            }        });    }    private void updateProcessInfo()    {        mText = "";        mTextView.setText(mText);        // 获取ActivityManager        ActivityManager activityManager = (ActivityManager) this                .getSystemService(Context.ACTIVITY_SERVICE);        // 更新时间        updateTimeInfo();        // 获取进程信息***************************************************        List<RunningAppProcessInfo> infos = activityManager                .getRunningAppProcesses();        for (RunningAppProcessInfo info : infos)        {            String name = info.processName;            mText = mTextView.getText().toString();            mText += name + "\n\n";            mTextView.setText(mText);        }    }    private void updateTimeInfo()    {        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式        String time = df.format(new Date());        System.out.println(time);// new Date()为获取当前系统时间        mTime.setText(time);    }}

我是天王盖地虎的分割线

参考:http://www.cnblogs.com/mengdd/p/3213378.html

更多相关文章

  1. 一款霸榜 GitHub 的开源 Linux 资源监视器!
  2. 安卓EditText控件底部红线如何解决?
  3. 王立平--include在Android应用
  4. SetContentView 到底Set去哪里呢?
  5. Android(安卓)开发遇到的问题
  6. android的软盘影响背景问题
  7. Android(安卓)ashmem
  8. android快捷设置标题样式布局
  9. Android(安卓)布局之FrameLayout

随机推荐

  1. 使用jquery在textarea中的颜色代码
  2. JSON/Jave不更新innerHTML onClick事件。
  3. 无法使用jquery将活动类添加到当前选定的
  4. C#Razor - 显示注释值,其中循环值等于sele
  5. JavaScript中的事件详解
  6. 如何使用jquery或JavaScript在一次浏览中
  7. javascript小实例,PC网页里的拖拽
  8. 深究js(三)——变量
  9. 尝试用jQuery创建旋转木马效果
  10. js中的indexOf以及startsWith和endsWith