小编Hes*_*sam的帖子

Android支持库如何工作?

据我所知,支持库正在使用,因为旧设备没有新的API.例如,他们不知道Fragment是什么以及如何实现它.因此,这些行为在支持库中定义.

因此,我的主要问题是,支持库中的Fragment库与它在API 11(Android v3.0,Honeycomb)中引入的双胞胎之间的区别是什么.

我的第二个问题是,如果可以将每个新API都放在支持库中,为什么我们有两种类型的库?我的意思是Android可以在支持库下发布所有API,而不是支持库和Android版本X.xx库.

android android-support-library

36
推荐指数
3
解决办法
9855
查看次数

android,如何重命名文件?

在我的应用程序中,我需要录制视频.在开始录制之前,我正在为其分配名称和目录.录制完成后,用户可以重命名他的文件.我写了下面的代码,但似乎不起作用.

当用户输入文件名并单击按钮时,我会这样做:

private void setFileName(String text) {     
        String currentFileName = videoURI.substring(videoURI.lastIndexOf("/"), videoURI.length());
        currentFileName = currentFileName.substring(1);
        Log.i("Current file name", currentFileName);

        File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), MEDIA_NAME);
        File from      = new File(directory, "currentFileName");
        File to        = new File(directory, text.trim() + ".mp4");
        from.renameTo(to);
        Log.i("Directory is", directory.toString());
        Log.i("Default path is", videoURI.toString());
        Log.i("From path is", from.toString());
        Log.i("To path is", to.toString());
    }
Run Code Online (Sandbox Code Playgroud)

文本:是用户输入的名称.当前文件名:是我在记录MEDIA_NAME之前分配的名称:文件夹名称

Logcat显示了这个:

05-03 11:56:37.295: I/Current file name(12866): Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/Directory is(12866): /mnt/sdcard/Movies/Mania-Karaoke
05-03 11:56:37.295: I/Default path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/From path is(12866): …
Run Code Online (Sandbox Code Playgroud)

android file-rename

35
推荐指数
4
解决办法
7万
查看次数

无法在 JPA @Entity 类中声明 List 属性。它说“基本”属性类型不应该是容器

我有一个 JPA @Entity class Place,其中的一些属性包含一些有关地点的信息,例如地点名称、描述和某些图像的 URL。

对于图像的 URL,我List<Link>在我的实体中声明了一个。

在此处输入图片说明

但是,我收到此错误:

Basic attribute type should not be a container.

我试图删除@Basic,但错误消息仍然存在。我不知道为什么它会显示此错误。

有什么帮助吗?

java hibernate jpa

27
推荐指数
5
解决办法
4万
查看次数

Android,List Adapter在getView中返回错误的位置

我发现了一个可能是错误的神秘问题!我的片段中有一个列表.每行都有一个按钮.列表不应响应单击但是按钮是可单击的.

为了获得点击的按钮,我创建了一个监听器并在我的片段中实现它.这是我的适配器的代码.

public class AddFriendsAdapter extends BaseAdapter {

    public interface OnAddFriendsListener {
        public void OnAddUserClicked(MutualFriends user);
    }

    private final String TAG = "*** AddFriendsAdapter ***";

    private Context context;
    private OnAddFriendsListener listener;
    private LayoutInflater myInflater;
    private ImageDownloader imageDownloader;
    private List<MutualFriends> userList;

    public AddFriendsAdapter(Context context) {
        this.context = context;
        myInflater = LayoutInflater.from(context);

        imageDownloader = ImageDownloader.getInstance(context);
    }

    public void setData(List<MutualFriends> userList) {
        this.userList = userList;

        Log.i(TAG, "List passed to the adapter.");
    }

    @Override
    public int getCount() {
        try {
            return userList.size();
        } catch …
Run Code Online (Sandbox Code Playgroud)

android html-lists baseadapter

23
推荐指数
1
解决办法
3万
查看次数

Android中的可扩展列表视图对点击没有反应,它不会扩展

我有一个可扩展的列表视图.我已经放了一些虚拟数据,并且evrything似乎没问题,但是当我运行应用程序时,所有组都处于折叠模式,当我点击它们时它们不会生效.这是截图:

在此输入图像描述

组的XML是:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/bg_slider"
    android:orientation="horizontal" >


    <TextView
        android:id="@+id/tvRecipeName"
        style="@style/normal_text.bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="5dp"
        android:focusable="false"
        android:lines="1"
        android:maxLines="1"
        android:text="@string/dd_title" />


    <ImageButton
        android:id="@+id/ibDeleteRecipe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="15dp"
        android:background="@color/transparent"
        android:contentDescription="@string/cd"
        android:focusable="false"
        android:src="@android:drawable/ic_menu_delete" />

    <View
        android:layout_width="1dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/tvRecipeName"
        android:focusable="false" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

孩子的XML是:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/White"
    android:gravity="left|center_vertical" >

    <View
        android:layout_width="1dp"
        android:layout_height="35dp"
        android:layout_toLeftOf="@+id/tvIngredient"
        android:focusable="false" />

    <TextView
        android:id="@+id/tvIngredient"
        style="@style/normal_text_black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="5dp"
        android:lines="1"
        android:maxLines="1"
        android:text="@string/dd_title"
        android:focusable="false" />

    <ImageButton
        android:id="@+id/ibDeleteIngredient"
        android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android expandablelistview

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

如何在Github的README.md文件中显示表?

我想在readme.md文件中显示一个表.我读了GitHub Flavored Markdown并按照它说的做了.所以这是我的表:

| Attempt | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | #11 | #12 |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| Seconds | 301 | 283 | 290 | 286 | 289 | 285 | 287 | 287 | 272 | …
Run Code Online (Sandbox Code Playgroud)

markdown github readme

21
推荐指数
4
解决办法
3万
查看次数

Eclipse,如何在XML文件中激活折叠?

我在用XML编写代码时遇到折叠问题.实际上,当我编写Java代码时没有问题,我可以扩展/折叠我的代码.

但是,在XML中,虽然它是活动的,但没有折叠图标.在侧栏(行号),我右键单击然后我选择Folding > Enable Folding栏的宽度变得更宽但我看不到折叠图标.我的屏幕背景是黑色是否可能这种颜色覆盖折叠图标?我不认为这是因为当我点击那些区域时没有任何反应.

xml eclipse folding

20
推荐指数
1
解决办法
3804
查看次数

Android,什么是不使用支持库时等效的DrawerLayout类?

由于我的最低SDK版本是14,我不想在我的应用程序中添加支持库.根据Android在DrawerLayout页面上的说法,此视图组在support library(android.support.v4.widget)中定义.

DrawerLayout如果我不添加支持库,是否有任何等效的类?谢谢.

android android-compatibility android-support-library drawerlayout

20
推荐指数
1
解决办法
2156
查看次数

Java,从数组中查找Kth最大值

我接受了Facebook的采访,他们问我这个问题.

假设您有一个带有N个不同值的无序数组

$ input = [3,6,2,8,9,4,5]

实现一个找到第K个最大值的函数.

EG:如果K = 0,则返回9.如果K = 1,则返回8.

我做的是这种方法.

private static int getMax(Integer[] input, int k)
{
    List<Integer> list = Arrays.asList(input);
    Set<Integer> set = new TreeSet<Integer>(list);

    list = new ArrayList<Integer>(set);
    int value = (list.size() - 1) - k;

    return list.get(value);
}
Run Code Online (Sandbox Code Playgroud)

我刚刚测试过,该方法可以根据问题正常工作.然而,受访者说,in order to make your life complex! lets assume that your array contains millions of numbers then your listing becomes too slow. What you do in this case? 作为提示,他建议使用min heap.根据我的知识,堆的每个子值不应超过根值.因此,在这种情况下,如果我们假设3是root,那么6是它的子节点,它的值比root的值更大.我可能错了,但您的想法是什么,它的实现基于min heap …

java arrays algorithm min-heap

19
推荐指数
2
解决办法
9924
查看次数

Android,如何发送HTML电子邮件并强制Android通过G-Mail发送它而不是其他应用程序?

我想通过我的申请发送电子邮件.我需要通过G-Mail发送基于HTML的电子邮件.我找到了以下解决方案,每个解决方案都有利有弊.

1)使用Intent(Intent.ACTION_SEND).这是非常简单的方式,我可以看到我的身体HTML格式,但问题是当我点击"发送电子邮件"按钮,因此很多应用程序,如Facebook和Google+弹出,这是无用的,我不应该在该列表中显示它.这是它的代码:

String html = "<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"MY EMAIL ADDRESS"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(html));
startActivity(Intent.createChooser(intent, "Send email..."));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

2)使用Intent(Intent.ACTION_SENDTO).这样过滤无用的应用程序,并向我显示邮件客户端.但它不会在gmail客户端中以HTML格式显示我的电子邮件.当我发送电子邮件时,一些客户端以HTML格式显示正文,而其他客户端不识别HTML,我的链接表现得像纯文本.这段代码如下:

String html = "<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO); …
Run Code Online (Sandbox Code Playgroud)

email android send android-intent

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