小编Har*_*elm的帖子

OnFocusChange并不总是有效

在我的一项活动中,我有三个EditText和一个OK按钮.该OnFocusChangeListener设置为所有三个EditText秒.每次焦点丢失时,听众都应该触发.

EditTexts 之间切换完美.但是,如果用户按下OK按钮,则在按下按钮之前没有为EditText用户聚焦触发的焦点改变(失去焦点).

我的代码出了什么问题?

private class MyOnFocusChangeListener implements OnFocusChangeListener {
    private EditText editText;

    public MyOnFocusChangeListener(final EditText editText) {
        super();

        this.editText = editText;
    }

    @Override
    public void onFocusChange(final View view, final boolean isFocused) {
        if (!isFocused) {
            if (editText == editText1) {
                // Do a calculation
            } else if (editText == editText2) {
                // Do another calculation
            } else if (editText == editText3) {
                // Do a different calculation
            }
        } …
Run Code Online (Sandbox Code Playgroud)

android focus android-edittext

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

有时:<nine-patch>需要有效的src属性

我有时会在我的应用程序中收到上述错误的报告.我在开发和测试期间从未看到过这个错误.应用程序适用于2.1及更高版本.我测试2.1,2.2和2.3(仿真器)和真实设备(2.3除外).

这是产生此错误的布局文件的一部分(视图是TableLayout的一部分):

 <TextView
 style="@style/ActivityTitleBar"
 android_layout_span="2"
 android:layout_weight="2"
 android:text="@string/txt_appname" />
Run Code Online (Sandbox Code Playgroud)

这是样式定义:

<style name="ActivityTitleBar">
<item name="android:background">@drawable/titlebar</item>
<item name="android:gravity">center</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">#fff</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在res/drawable中是一个包含以下内容的XML文件:

<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="@drawable/titlebar" />
Run Code Online (Sandbox Code Playgroud)

titlebar.png位于我的drawable-hdpi,drawable-ldpi和drawable-mdpi文件夹中.

我不知道什么设备或Android版本导致此错误.

有任何想法吗?

提前谢谢了.

HJW

这是stack-trace-report:

java.lang.RuntimeException: Unable to start activity ComponentInfo{de.x.y.android/de.x.y.android.Main}: android.view.InflateException: Binary XML file line #18: Error inflating class android.widget.TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at …
Run Code Online (Sandbox Code Playgroud)

resources png android styles

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

keySet().toArray(new Double [0])做什么?

以下返回有什么作用?我该如何使用该值:

private Map<Double, String> theLabels = new HashMap<Double, String>();

public Double[] getTheLabels() {
  return theLabels.keySet().toArray(new Double[0]);
  }
Run Code Online (Sandbox Code Playgroud)

它是否正确?

Double[] aD = theClassInQuestion.getTheLabels();
Run Code Online (Sandbox Code Playgroud)

提前致谢.

HJW

java map

6
推荐指数
2
解决办法
6173
查看次数

Stuck with porting from activity to fragment

It's now one week exactly that I try to port a simple activity-based app to fragments. I'm totally stuck.

This beast is a simple List, Details, Add/Edit app with contextmenu and optionmenus. I tried to make it right: Fragments and activities each in their own file, using the v4 support-package for phone and tablet, fragments do everything a re-usable fragment should do and callbacks (lots of them) fly around to inform activities and fragments about what to do. Converting from …

android fragment android-activity

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

apps-screens标签出现在应用标签之后?

自我最近更新SDK和Eclipse以来,Eclipse中报告了以下问题.这是什么意思?我应该在哪里放置support-screen标签?

在<application>标记之后出现<supports-screens>标记

这是我的应用程序的典型清单:

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

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="preferExternal" 
    android:versionCode="1"
    android:versionName="1.1"
    package="aa.bb.cc" >

    <application
    android:hardwareAccelerated="true"
        android:icon="@drawable/cc"
        android:label="@string/txt_appname"
        android:name="MyApplication" >

        <activity
            android:name="ActivityA" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="ActivityB" >

            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

        <activity android:name="MoreActivities"></activity>

        <service android:name="MyService"></service>

        <uses-library android:name="com.google.android.maps" />
    </application>

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true" 
        android:normalScreens="true" 
        android:smallScreens="true" />

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

    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_CONTACTS" …
Run Code Online (Sandbox Code Playgroud)

android manifest

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

如何在Eclipse中安装旧的ADT13

使用SDK14/ADT14时,我们的Android应用程序存在很多问题.目前,我们无法构建包含大量库和相关项目的复杂应用程序(即使在清理,刷新,强制保存后,资源也不会更新......).我们想回到SDK13/ADT13.

SDK13在我们的备份库中.但是我们没有ADT13插件.

我们如何指导Eclipse下载旧的ADT13插件?

提前谢谢了.

eclipse sdk android adt

4
推荐指数
1
解决办法
3314
查看次数

如何配置Eclipse/Android插件来忽略desktop.ini文件?

只要在其中一个项目目录中有desktop.ini文件(例如res/values/desktop.ini),Eclipse和Android Tools插件组合就无法构建.

我希望Eclipse和/或Android Tools插件忽略desktop.ini文件.这可能吗?如果有,怎么样?

提前致谢.

eclipse android

4
推荐指数
1
解决办法
2631
查看次数

如何在Adapter和Activity之间进行通信

我不确定从适配器到相应的Activity的最佳通信方式是什么.

我的活动有一个布局,上面有一个WebView和一个Gallery:

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

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical" >

    <Gallery 
        android:id="@+id/gallery"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:spacing="2dip" />       

    <WebView
        android:id="@+id/webview"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:layout_width="fill_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

活动将图像数据加载到图库中:

public class MyActivity extends Activity {

  private MyAdapter            adapter;
  private Container            container;
  private ArrayList<Container> containers = new ArrayList<Container>();
  private Gallery              gallery;
  private WebView              webView;

  @Override
  public void onCreate(Bundle bundle) {
    ...
    gallery = (Gallery) findViewById(R.id.gallery);
    webView = (WebView) findViewById(R.id.webview);

    containers = fetchContainers();
    doGallery();
  }

  private void doGallery() {
    adapter = new MyAdapter(this,
                            containers);
    gallery.setAdapter(adapter); …
Run Code Online (Sandbox Code Playgroud)

android adapter android-activity

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

newChooseAccountIntent返回一个Name,但getToken需要一个Email

我从新的Google Play服务开始,尝试使用我在博客和参考示例中找到的信息来创建一个完整的应用程序.恕我直言,这些例子中缺少一些东西.

新标准AccountPicker.newChooseAccountIntent可用于选择在设备上注册的Google帐户.使用该对话框返回返回时帐户的名称.

现在,这些示例显示了如何获取令牌.新的GoogleAuthUtil.getToken方法需要一封电子邮件来获取令牌.

有些东西不见了.如何从给定的帐户名称获取电子邮件?

提前谢谢了.

public class MyActivity extends Activity {

    public static final String AUTHTOKENSCOPE_DRIVE = "oauth2:https://www.googleapis.com/auth/drive";

    String accountName = "";

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
                    // Need to fetch token with email
                    // String token = GoogleAuthUtil.getToken(this, <???email???>,  
                           AUTHTOKENSCOPE_DRIVE);
                } else {
                }

                break;
            default:
                super.onActivityResult(requestCode, resultCode, intent);
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); …
Run Code Online (Sandbox Code Playgroud)

android google-play-services

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

FragmentActivity上的ActivityNotFoundException

我在Play商店中有很多基于活动的简单应用程序.两天后,我尝试用Fragments做我的第一步.我还是不明白.我已经阅读了大部分关于Fragments的所有文档,博客和指南,但是我的愚蠢的简单测试应用程序拒绝以MyActivity上的ClassNotFoundException开头.

所以这就是我到目前为止所做的:

起始的FragmentActivity称为MyActivity:

public class MyActivity extends FragmentActivity {

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        setContentView(R.layout.myactivity);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是layout/myactivity.xml:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

    <fragment
        class="com.test.app.Table1List"
        android:id="@+id/table1list"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是ListFragment及其XML文件:

public class Table1List extends ListFragment {

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (viewGroup == null) {
            return null;
        }

        return layoutInflater.inflate(R.layout.table1list, viewGroup);
    }
}

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ListView
        android:drawSelectorOnTop="false"
        android:fastScrollEnabled="true" 
        android:id="@id/android:list"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent" />

    <TextView
        style="@style/TextViewMedium"
        android:id="@id/android:empty"
        android:text="@string/txt_noresult" …
Run Code Online (Sandbox Code Playgroud)

android fragment android-fragmentactivity

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

如何使用Google Drive SDK进行排序?

我正在使用以下方法从Google云端硬盘查询条目.在我的Android应用程序中,我不会立即获取目录的所有条目.使用延迟加载,我在用户滚动列表时获取条目.

问题是条目未分类.我把它们排在我的身边,但是懒惰的装载会变得很糟糕.我只能对我所拥有的内容进行排序,因此列表必须与每个加载的新页面一起使用.

我怎么能改变呢?

    FileList files = drive
            .files()
            .list()
            .setMaxResults(GdataConstants.REQUEST_ENTRIESPERPAGE)
            .setPageToken(nextPageToken)
            .setQ(buildFilesQuery(folderId, mimeTypes))
            .execute();
Run Code Online (Sandbox Code Playgroud)

android google-drive-api

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