小编kga*_*oid的帖子

当ListView为空时显示空视图

由于某种原因,即使ListView不为空,也会出现空视图(本例中为TextView).我以为ListView会自动检测何时显示空视图.

<RelativeLayout android:id="@+id/LinearLayoutAR"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <ListView android:id="@+id/ARListView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"></ListView>
    <ProgressBar android:id="@+id/arProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"></ProgressBar>
    <!-- Here is the view to show if the list is emtpy -->
    <TextView android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="No Results" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

如何正确连接空视图?

android listview

131
推荐指数
8
解决办法
16万
查看次数

如何按名称从res/raw读取文件

我想从res/raw /文件夹中打开一个文件.我绝对相信文件存在.要打开我试过的文件

File ddd = new File("res/raw/example.png");
Run Code Online (Sandbox Code Playgroud)

命令

ddd.exists(); 
Run Code Online (Sandbox Code Playgroud)

收益率为假.所以这种方法不起作用.

MyContext.getAssets().open("example.png");
Run Code Online (Sandbox Code Playgroud)

以getMessage()"null"结束异常.

简单地使用

R.raw.example
Run Code Online (Sandbox Code Playgroud)

因为文件名仅在运行时作为字符串被识别,所以是不可能的.

为什么访问文件夹/ res/raw /中的文件如此困难?

file-io resources android

76
推荐指数
4
解决办法
13万
查看次数

消费者关闭输入通道或发生错误.事件= 0x8中

01-03 11:28:47.499: ERROR/InputDispatcher(164): channel '4085fe50 com.bce.tip/com.bce.tip.core.MenuActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
01-03 11:28:47.499: ERROR/InputDispatcher(164): channel '4085fe50 com.bce.tip/com.bce.tip.core.MenuActivity (server)' ~ Channel is unrecoverably broken and will be disposed!`
Run Code Online (Sandbox Code Playgroud)

当我点击Imageview动作调用时,我正在调用这个onclick到另一个图层类

android

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

通过编程获取从图库中选择的图像大小(以kb或mb为单位)

我正在从图库中选择图像,我想以编程方式确定图像的大小(kb或mb)。这是我写的:

public String calculateFileSize(Uri filepath)
{
    //String filepathstr=filepath.toString();
    File file = new File(filepath.getPath());

    // Get length of file in bytes
    long fileSizeInBytes = file.length();
    // Convert the bytes to Kilobytes (1 KB = 1024 Bytes)
    long fileSizeInKB = fileSizeInBytes / 1024;
    // Convert the KB to MegaBytes (1 MB = 1024 KBytes)
    long fileSizeInMB = fileSizeInKB / 1024;

    String calString=Long.toString(fileSizeInMB);
    return calString;
}
Run Code Online (Sandbox Code Playgroud)

从图库中选择图像的uri来的很完美。但是值fileSizeInBytes是零。从图库中onActivityResult选择图像后,我在调用此方法。之前我在这里看到了几个相同的问题。但是没有一个对我有用。有什么办法吗?

android uri file filesize android-gallery

6
推荐指数
1
解决办法
9770
查看次数

在弹出窗口中显示RecyclerView

我有一个RecyclerView,当单击RecyclerView项时,想要打开一个包含另一个RecyclerView的弹出窗口。差不多完成了,但是在弹出窗口中,没有显示名片视图。我不知道为什么,有人可以帮忙吗?

1- 我的主RecyclerView适配器

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>    {

private ArrayList<Mission> mDataset;
private Context mContext;

// Provide a suitable constructor (depends on the kind of dataset)
public MyAdapter(ArrayList<Mission> myDataset, Context context) {
    mDataset = myDataset;
    this.mContext = context;
}

// Create new views (invoked by the layout manager)
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    // create a new view
    View v = LayoutInflater.from(mContext)
            .inflate(R.layout.mission_card_item, parent, false);
    // set the view's size, margins, paddings and layout parameters
    MyViewHolder vh …
Run Code Online (Sandbox Code Playgroud)

android popup android-cardview android-recyclerview

6
推荐指数
1
解决办法
8162
查看次数

Twitter Oauth回调getOAuthRequestToken为null

我在这里使用应用程序的示例https://github.com/itog/Twitter4j-android-Sample,它正在工作.我在我的应用程序中使用相同的方法,但是当我在线时它返回null

static final String CALLBACK_URL = "oauth://t4jsample"; [Copy the same as the Sample]
requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
Run Code Online (Sandbox Code Playgroud)

这是我的清单

<activity
        android:name="com.my.app.SharePreviewActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden|adjustPan" >

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="t4jsample"
                android:scheme="oauth" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

这是我从示例应用程序中复制的其他代码.

private void askOAuth() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
    Configuration configuration = configurationBuilder.build();
    twitter = new TwitterFactory(configuration).getInstance();

    try {
        requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
        Toast.makeText(this, "Please authorize this app!",
                Toast.LENGTH_LONG).show();
        this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
                .parse(requestToken.getAuthenticationURL())));
    } catch (TwitterException e) …
Run Code Online (Sandbox Code Playgroud)

twitter android twitter4j twitter-oauth

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

带有python请求库的zomato api请求

Zomato是最受欢迎的餐厅搜索引擎之一,提供免费的api服务......

如果在api请求中使用curl,则效果很好;

curl -X GET --header "Accept: application/json" --header "user_key: MY_API_KEY_HERE" "https://developers.zomato.com/api/v2.1/geocode?lat=41.10867962215988&lon=29.01834726333618"
Run Code Online (Sandbox Code Playgroud)

但是使用Python的requests库,它不起作用.当我执行下面的代码时;

import requests
r = requests.get("https://developers.zomato.com/api/v2.1/geocode?lat=41.10867962215988&lon=29.01834726333618", headers={"user_key": "MY_API_KEY_HERE", "Accept": "application/json"});
Run Code Online (Sandbox Code Playgroud)

解释器返回以下错误;

requests.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 403 Forbidden.
Run Code Online (Sandbox Code Playgroud)

通过pyCurl库进行了几次尝试但不幸的结果是相同的;403 Forbidden

我该如何解决这个问题?

python json pycurl python-requests zomato-api

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

无法从hashmap的arraylist中删除重复元素

我从内容提供商处获取联系人,我需要在列表视图中显示它们.在此过程中,我成功获取联系人,但它们包含重复的值.现在每个联系人都没有Phone.CONTACT_ID.我想过滤我的联系人列表基于该特定领域.

这是代码:

try {
            cursor = getApplicationContext().getContentResolver()
                    .query(Phone.CONTENT_URI, null, null, null, null);
            int Idx = cursor.getColumnIndex(Phone.CONTACT_ID);
            int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);

            int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
            int photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_THUMBNAIL_URI);
            cursor.moveToFirst();
            do {
                System.out.println("=====>in while");
                HashMap<String, String> hashMap = new HashMap<String, String>();

                contactid=cursor.getString(Idx);
                name = cursor.getString(nameIdx);
                phoneNumber = cursor.getString(phoneNumberIdx);
                image = cursor.getString(photoIdIdx);
                System.out.println("Id--->"+contactid+"Name--->"+name);

                if (!phoneNumber.contains("*")) {
                    hashMap.put("contactid", "" + contactid);
                    hashMap.put("name", "" + name);
                    hashMap.put("phoneNumber", "" + phoneNumber);
                    hashMap.put("image", "" + image);
                    // hashMap.put("email", ""+email);
                              hashMapsArrayList.add(hashMap);
                }

            } …
Run Code Online (Sandbox Code Playgroud)

android arraylist contacts

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

使用快捷方式android分享意图

从应用商店下载应用时,默认情况下,iOS 在快捷方式选项中提供“共享应用名称”选项。

请参考下图:

在此处输入图片说明

当单击它时,它将在电话菜单屏幕本身中打开共享意图,而无需重定向到应用程序,用户可以在其中共享应用程序。

在此处输入图片说明

我想在android中实现它

到目前为止,这是我尝试过的:

<shortcut
        android:shortcutId="share_app"
        android:enabled="true"
        android:icon="@drawable/ic_cart_active"
        android:shortcutShortLabel="@string/shortcut_share"
        android:shortcutLongLabel="@string/shortcut_share">
        <intent
            android:action="android.intent.action.send"
            android:targetPackage="com.example.android.internal"
            android:targetClass="" />
    </shortcut>
Run Code Online (Sandbox Code Playgroud)

但这是行不通的,因为我无法理解,这里的targetClass应该是什么 。

编辑: Nilesh的答案几乎奏效,但是我现在面临的唯一问题是,每当我从快捷方式单击共享按钮时,启动器活动就会显示一秒钟,然后显示共享意图选择器现在,当我按下显示共享选项的主屏幕按钮时,该应用将进入后台。这不应该发生。任何想法如何避免这种情况。

在此处输入图片说明

android android-shortcut

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

无法测试应用程序订阅

我找不到通过谷歌测试InApp订阅测试产品ID的方法private final String productID = "android.test.purchased"; // Test Product ID by Google

文档中,没有任何地方写入InAPP订阅无法使用测试产品进行测试,也没有在任何地方提及,如何测试InApp订阅.

我已按照文档(InAppV3)实现了我的代码.

医生说:

实施订阅:启动订阅的购买流程类似于启动产品的购买流程,但产品类型必须设置为"subs".购买结果将传递到您的Activity的onActivityResult方法,与应用内商品的情况完全相同.

我也正确地实施了这一点.

我的应用程序正在工作,如果我用"subs"替换"inapp",即它适用于产品而不是订阅.

当我将"inapp"更改为"subs"时,购买将返回:

09-24 14:01:12.943: I/(16929): isBillingSupported() - success : return 0
09-24 14:01:12.943: D/Finsky(2598): [281] InAppBillingUtils.getPreferredAccount: com.kgandroid.inappsubscriptiondemo: Account from first account - [MOn42QuZgF98vxJi0p3wAN3rfzQ]
09-24 14:01:12.943: I/(16929): getPurchases() - success return Bundle
09-24 14:01:12.943: I/(16929): getPurchases() - "RESPONSE_CODE" return 0
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_ITEM_LIST" return []
09-24 …
Run Code Online (Sandbox Code Playgroud)

android in-app-purchase in-app-subscription

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