小编Hou*_*fly的帖子

如何在edittext上禁用键盘弹出?

在我的应用程序中,我所有屏幕的第一个视图是EditText,因此每次进入屏幕时,屏幕键盘都会弹出.如何禁用此弹出窗口并在手动单击EditText时启用它?

    eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);

    eT.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {

            if(hasFocus){
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
            imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

xml代码:

<ImageView
    android:id="@+id/feedPageLogo"
    android:layout_width="45dp"
    android:layout_height="45dp"
    android:src="@drawable/wic_logo_small" />

<Button
    android:id="@+id/goButton_feed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/go" />

<EditText
    android:id="@+id/searchAutoCompleteTextView_feed"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/goButton_feed"
    android:layout_toRightOf="@id/feedPageLogo"
    android:hint="@string/search" />

<TextView
    android:id="@+id/feedLabel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/feedPageLogo"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/feed"
    android:textColor="@color/white" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ButtonsLayout_feed"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button
        android:id="@+id/feedButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:background="@color/white"
        android:text="@string/feed"
        android:textColor="@color/black" />

    <Button
        android:id="@+id/iWantButton_feed"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_margin="0dp"
        android:layout_weight="1" …
Run Code Online (Sandbox Code Playgroud)

android android-edittext

81
推荐指数
8
解决办法
14万
查看次数

如何在运行时将部分文本Bold在android中?

一个ListView在我的应用程序有很多字符串元素,如name,experience,date of joining,等我只是想name大胆.所有字符串元素都在一个单独的元素中TextView.

我的XML:

<ImageView
    android:id="@+id/logo"
    android:layout_width="55dp"
    android:layout_height="55dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="15dp" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/logo"
    android:padding="5dp"
    android:textSize="12dp" >
</TextView>
Run Code Online (Sandbox Code Playgroud)

我的代码设置ListView项的TextView:

holder.text.setText(name + "\n" + expirience + " " + dateOfJoininf);
Run Code Online (Sandbox Code Playgroud)

android android-listview

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

android.content.ActivityNotFoundException:无法找到显式活动类

我收到此错误:

06-06 10:45:19.685: E/AndroidRuntime(554): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.Android.myApp/com.Android.myApp.Facebook.Example}; have you declared this activity in your AndroidManifest.xml?
Run Code Online (Sandbox Code Playgroud)

但我已经在我的清单文件中声明了它.可能是这种例外的其他原因是什么?

我的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Android.myApp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />

    <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light" >

        <activity
            android:name=".SignUpActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SignInActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".HomeActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".selectCityActivity" …
Run Code Online (Sandbox Code Playgroud)

android classnotfoundexception

20
推荐指数
3
解决办法
6万
查看次数

使用getCacheDir()缓存文件

我想下载从Dropbox下载的图像并将其缓存以供进一步使用:

String cachePath = mContext.getCacheDir().getAbsolutePath() + entry.fileName();
File cacheFile = new File(cachePath);
//cacheFile.exists() returns true after 1st call
if(!cacheFile.exists()){
  //If cache doesn't exist, download the file
  mFos = new FileOutputStream(cachePath);
  mApi.getThumbnail(path, mFos, ThumbSize.BESTFIT_320x240,
                              ThumbFormat.JPEG, null);
}
mDrawable = Drawable.createFromPath(cachePath);
mImageView.setImageDrawable(mDrawable);
Run Code Online (Sandbox Code Playgroud)

mDrawablenull如果代码不进入if块.

如果我评论if条件它工作正常.但每次下载图像.

编辑:

以上代码来自如何测试缓存中的文件

android caching dropbox

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

从活动中调用摄像头,捕获图像并上载到服务器

在我的应用程序中,我有一个调用摄像头的button1,在捕获图像后,它必须保存到设备库中.当我点击button2时,它必须打开图库,并要求选择图片.选中后,必须在这些按钮下方的imageView上显示.

这是我的代码:

package com.android.imageuploading;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageUploadingActivity extends Activity {
    private static final int REQUEST_CODE = 1;
    private Bitmap bitmap;
    private ImageView imageView;
    private Button button_1;
    public int TAKE_PICTURE = 1;
    private Button button_2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) …
Run Code Online (Sandbox Code Playgroud)

android image android-camera

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

AutoCompleteTextView不显示任何下拉项

我的XML:

<AutoCompleteTextView
        android:id="@+id/searchAutoCompleteTextView_feed"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:completionThreshold="2"
        android:hint="@string/search" />
Run Code Online (Sandbox Code Playgroud)

我的java代码:

AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed);
eT.addTextChangedListener(this);
String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"};
ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa);
eT.setAdapter(aAdapter);
Run Code Online (Sandbox Code Playgroud)

这不起作用....我的意思是它只是像EditTextView一样工作.我哪里错了?

完整代码:

public class FeedListViewActivity extends ListActivity implements TextWatcher{


    private AutoCompleteTextView eT;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.feed);

        eT = (AutoCompleteTextView) findViewById(R.id.searchAutoCompleteTextView_feed);
        eT.addTextChangedListener(this);

                    Thread thread = new Thread(null, loadMoreListItems);
                    thread.start();
    }

    private Runnable returnRes = new Runnable() {
        public void run() {

            //code for other purposes …
Run Code Online (Sandbox Code Playgroud)

android autocompletetextview

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

片段中的广播接收器

我的片段中有一个广播接收器,用于跟踪任何新收到的短信.

private BroadcastReceiver smsBroadcastReceiver;
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    smsBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e("smsBroadcastReceiver", "onReceive");
        }
    };
}

@Override
public void onStart() {
super.onStart();
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(smsBroadcastReceiver, filter);
}

@Override
public void onStop() {
    super.onStop();
    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(smsBroadcastReceiver);
}
Run Code Online (Sandbox Code Playgroud)

和Manifest中的权限:

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
Run Code Online (Sandbox Code Playgroud)

问题是我从来没有得到日志Log.e("smsBroadcastReceiver", "onReceive"); 我肯定得到短信,而接收器仍然注册.

但是,如果我将接收器作为一个单独的类编写并将其放入Manifest中,则调用onReceive().

我错过了什么?

android broadcastreceiver

8
推荐指数
1
解决办法
9455
查看次数

Salesforce MobileSDK:未为此组织启用Rest API

我正在尝试将Salesforce Mobile SDK用于原生Android.需求:

  1. 允许任何拥有Salesforce帐户的用户登录
  2. 获取他/她的联系人列表
  3. 获取特定联系人详细信息

如果这些不属于Mobile SDK,请告知我们.

我关注https://github.com/forcedotcom/SalesforceMobileSDK-Android:

  1. 克隆它
  2. 安装NPM并安装所需的子模块
  3. 使用原生的forceroid创建了一个新的Android应用程序
  4. bootconfig.xml使用我连接的应用程序的值更改了值.

它记录正常,但当我尝试获取联系人时,它说:

未为此组织启用Rest API

在此输入图像描述

登录响应似乎没问题.客户端对象json凭据:

{
  "clientId": "*******",
  "loginUrl": "https://login.salesforce.com",
  "identityUrl": "https://login.salesforce.com/id/99VVHJHGF5688/00548000003yOKeAAM",
  "instanceUrl": "https://ap2.salesforce.com",
  "userId": "**********",
  "orgId": "*********",
  "communityUrl": null,
  "refreshToken": "*************",
  "accessToken": "************",
  "communityId": null,
  "userAgent": "SalesforceMobileSDK/4.3.0 android mobile/7.0 (Nexus 6P) SFTest/1.0 Native uid_32aea9bdde1b8b7e"
}
Run Code Online (Sandbox Code Playgroud)

编辑1:获取联系人列表的代码:

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Contact");
}

private void sendRequest(String soql) throws UnsupportedEncodingException {
    RestRequest restRequest = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(this), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() …
Run Code Online (Sandbox Code Playgroud)

android salesforce

7
推荐指数
1
解决办法
194
查看次数

从网上下载文本文件

我想从网址下载文本文件并将其保存在设备本地,并在我的应用中使用它.

码:

try {
    File file = new File(getFilesDir(), "file.txt");
    if (file.length() > 0) {
        //File already exists and it is not empty
        return;
    }
    URL url = new URL("https://www.abc.com/file.txt");
    FileOutputStream fos = new FileOutputStream(file);
    InputStream in = url.openStream();
    byte[] buffer = new byte[1024];
    int length = 0;
    while ((length = in.read(buffer)) > 0) {
        fos.write(buffer, 0, length);
    }
    fos.flush();
    fos.close();
} catch (Exception e) {
    // TODO: 
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,代码依赖于getFilesDir()假设始终存在.但是,通过适当的网络连接和权限,几乎没有问题:

  1. getFilesDir()在任何情况下我都会失败吗?
  2. 有没有任何文件没有下载/错误的内容等..,这个代码?
  3. 一旦我遇到文件被下载但有所有编码字符的问题,无论我多么下载它,它仍然具有相同的编码文本.只有当我重新安装我的应用程序时,才会下载正确的文本.从那时起,从未有过这个问题.这种怪异行为的原因是什么?

编辑: 当我尝试读取我在logcat中显示的下载文件(有时会发生在10中)时,我得到的内容是:

在此输入图像描述

用于读取文件的代码:

BufferedReader …
Run Code Online (Sandbox Code Playgroud)

android

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

有没有办法避免在浏览器中打开链接

使用Huawei App Links时(因为Firebase动态链接不适用于Huawei App Gallery),生成的就是这种长链接。

https://example.drcn.agconnect.link/?deeplink=https%3A%2F%2Fexample.com%2Freferral%2F3c3432x&android_deeplink=https%3A%2F%2Fexample.com%2Freferral%2F3c3432x&android_open_type=2&android_package_name=com.example.mobile

当在未安装我的应用程序的 Android(Google) 设备上单击此链接时,我会看到以下选项:

在此输入图像描述

“打开”-在浏览器中打开深层链接,即https://example.com/referral/3c3432x

“下载”- 使用我的应用程序页面打开 Google Play 商店应用程序

下载行为很好,但我不想要打开行为,因为该链接实际上不存在。据我所知,仍然可以在桌面上访问此链接,并且可能会尝试在浏览器上访问该链接,但目前我们可以在这种情况下显示 404。

有没有办法避免“打开”选项?或者更好的是停止显示此屏幕并立即重定向到应用程序(如果已安装)或播放商店(未安装)。就像 Firebase 的做法一样。

我什至尝试了这里列出的landing_page_type=2选项:https: //developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-applinking-createlinks-define-0000001055514692但这并没有似乎不起作用,它总是显示打开/下载页面,无论值如何。

deep-linking huawei-mobile-services

5
推荐指数
0
解决办法
251
查看次数