0

これをテキストビューに入れるにはどうすればよいですか?

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
memoryInfo.availMem;

テキストビュー ID は、たとえばfreemem. textview は swipeview.thans の 2 番目のタブにあります

4

1 に答える 1

2

これをレイアウト XML に入れます

  <TextView android:id="@+id/myTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

そしてこれはあなたの活動で:

   TextView myTextView = (TextView)findViewById(R.id.myTextView);
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    myTextView.setText("" + memoryInfo.availMem);

memoryInfo.availMem は、システムで使用可能なメモリです。memoryInfo.totalMem は、カーネルがアクセスできるメモリの合計です。

これは、メモリの可用性に関する適切な回答へのリンクです。

于 2013-06-14T02:43:22.543 に答える