小编cod*_*ewb的帖子

android - java - 带有ArrayList的WeakReferences?

我知道WeakReference,如果我做了WeakReference一些东西,除非直接引用它,它将是下一个GC循环收集的垃圾.我的问题是,如果我做出ArrayListWeakReferenceS'

例如:

ArrayList<WeakReference<String>> exArrayList;
exArrayList = new ArrayList<WeakReference<String>>();
exArrayList.add(new WeakReference<String>("Hello"));
Run Code Online (Sandbox Code Playgroud)

我现在可以访问数据了exArrayList.get(0).get().

我的问题变成了:这是WeakReference数据,exArrayList.get(0)下一个GC循环中的数据是否会被GC进行?(即使我没有另外直接引用它)或者这个特定的参考是否会一直存在直到arraylist被清空?(例如:) exArrayList.clear();.

如果这是重复,我没有在谷歌中找到我的关键字.

java android garbage-collection weak-references arraylist

10
推荐指数
2
解决办法
1万
查看次数

声明一个弱引用数组?

我知道如何声明一个 individual WeakReference,但是一个数组呢?

    WeakReference<String> testWR;
    testWR = new WeakReference<String>("Hello");

    String[] exStrArr;
    exStrArr = new String[5];

    WeakReference<String>[] testWR2;
    //not working
    testWR2 = new WeakReference<String>[5];
    testWR2 = new WeakReference<String>(new String())[5];
    testWR2 = new WeakReference<String>()[5];
Run Code Online (Sandbox Code Playgroud)

有人可以在这里告诉我正确的语法吗?我一定会很感激的 =)

java weak-references

5
推荐指数
1
解决办法
1450
查看次数

Android DialogFragment布局,奇数额外空格

所以在制作一个dialogfragment简单的"有用户选择"弹出窗口之后,我加载它并在布局中看到一些奇怪的额外空白,我不确定是什么导致它并且我一直在困扰我的大脑试图解决它.我稍微修改了xml以更好地显示行为,唯一的区别是我已将3个垂直部分的宽度从"match_parent"更改为"wrap_content",因此我可以使用边框来显示空白的实际大小.这是一张显示问题的图片:

问题

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/pictureSourceMainTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/tvborder"
        android:gravity="center"
        android:text="Where would you like to choose\nyour image from?"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:id="@+id/pictureSourceIVLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/tvborder"
        android:weightSum="3" >

        <ImageView
            android:id="@+id/pictureSourceCancelIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/pictureSourceGalleryIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/pictureSourceCameraIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/pictureSourceTVLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:weightSum="3" >

        <TextView
            android:id="@+id/pictureSourceCancelTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/tvborder"
            android:gravity="center"
            android:text="Cancel" />

        <TextView
            android:id="@+id/pictureSourceGalleryTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/tvborder" …
Run Code Online (Sandbox Code Playgroud)

layout android dialogfragment

2
推荐指数
1
解决办法
2055
查看次数