小编Arc*_*pgc的帖子

ListView.onItemClick不起作用

我在活动中的ListView:

    ListView listView1 = (ListView) menu.findViewById(R.id.menuList);
    String menuItems[] = new String[] { "My Wants", "Profile", "Notifications",
            "Feedback", "Logout" };
    listView1.setAdapter(new SideMenuAdapter(this, menuItems, listView1));
    listView1.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            if (position == 1) {
                Intent intent = new Intent(FeedListViewActivity.this,
                        UserProfileActivity.class);
                startActivity(intent);
            }
            if (position == 0) {
                showMyWants();
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

菜单是:

menu = inflater.inflate(R.layout.horz_scroll_menu, null);
Run Code Online (Sandbox Code Playgroud)

horz_scroll_menu.xml是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/menu"
    android:layout_width="1dp"
    android:layout_height="1dp"
    android:background="#FFFFFFFF"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FF000000" …
Run Code Online (Sandbox Code Playgroud)

android onitemclicklistener

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

API 10中的Notifications.Builder

Notification.Builder builder = new Notification.Builder(this);

builder.setContentIntent(contentIntent)
    .setSmallIcon(R.drawable.ic_launcher)
    .setTicker(notificationMessage)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(true)
    .setContentTitle(newNotificationsCount + " New Notifications")
    .setContentText(notificationMessage);

Notification notification = builder.getNotification();
nm.notify(R.string.app_name, notification);
Run Code Online (Sandbox Code Playgroud)

这给出了错误:

调用需要API级别11(当前最小值为10):android.app.Notification $ Builder #setContentIntent

我下载了android.support.v4.jar将它添加到与srcres等目录相同的libs文件夹中.

右键单击项目资源管理器中的jar并添加到构建路径.

我的应用程序有一个最小api = 10目标api = 15

谢谢

notifications android

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

如何在android中显示"应用程序已崩溃,但报告被发送到管理员"的消息

我是Android新手,我的应用程序涉及大量的互联网访问,很多时候,当需要来自Web服务的数据不可用时,我的应用程序崩溃了.

我试图避免尽可能多的情况,但我不确定我的应用程序是否没有崩溃.

我正在使用名为"delight circle"的应用程序,有时该应用程序崩溃并向我显示此Toast:

"应用程序崩溃,并向管理员发送报告"

并带我回到之前的活动或上一个动作,从这里我可以再次正常使用该应用程序.

我有两个问题:

  1. 如何在应用程序崩溃一次后使应用程序正常工作.在我的应用程序中,如果它崩溃然后它要求我关闭力量,当我点击它,它带我到前一个活动(或行动),但没有任何工作,如果我试图做任何事情,它要求力量再次关闭,我最终强制关闭应用程序从设置 - >应用程序 - > myApp - > foce关闭.

  2. 如何发送实际导致应用程序崩溃的报告?现在我在每个活动中都有很多日志,所以现在如果它崩溃我可以找出确切的原因并解决.但是当我发布应用程序时,我该怎么做?

谢谢

crash android crash-reports

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

onClickListener无法在我的活动中工作

我的布局有13个TextViews,点击后会改变ListView项目.

这是我的活动:

public class ExampleActivity extends ListActivity implements
        OnClickListener {

    private String[] sa = new String[100];
    private ListView lv;
    private Context context = this;
    private ArrayAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new LongOperation().execute("1");
        lv = getListView();
    }

    private class LongOperation extends AsyncTask<String, Void, String> {

        private ProgressDialog dialog = new ProgressDialog(
                ExampleActivity.this);

        @Override
        protected String doInBackground(String... params) {

            int i = Integer.parseInt(params[0]);
            for (int n = 0; n < 100; n++) {
                if (i != 5 …
Run Code Online (Sandbox Code Playgroud)

android onclick

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

使用actionbar sherlock时找不到类

我从主站点本身下载了actionbar sherlock库.我试图在我的应用程序中使用它.

import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;

public class Sherlockactivity extends SherlockActivity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
Run Code Online (Sandbox Code Playgroud)

}

但是当我使用默认的main.xml布局启动应用程序时,我得到了这个异常.

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.sherlock/com.android.sherlock.SherlockActivity}: java.lang.ClassNotFoundException: com.android.sherlock.SherlockActivity in loader dalvik.system.PathClassLoader[/data/app/com.android.sherlock-1.apk]
Run Code Online (Sandbox Code Playgroud)

我的清单:

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="14" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >
        <activity
            android:name=".SherlockActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

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

我刚开始使用支持库.不知道如何解决这个问题.

谢谢

android actionbarsherlock

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

Android:如何在单击后退按钮时隐藏滑动菜单

我在用 :

https://github.com/iPaulPro/SlidingMenu

库像滑动菜单一样实现Facebook,以及ActionBarSherlock库.

在我的例子中,BehindContentView是一个ListFragment.

1.单击图像以获取后视图(调用toggle();).

2. onListItemClicked转到Activity_2,显示单击项目的文本.

3.在此Activity_2中,当我单击设备后退按钮时,我得到主Activity_1但后面的View是打开的.通常在Facebook或Google+中的行为是,当您从任何其他活动返回到Activity_1时,隐藏了后视图.

4.此外,即使在拥有这些线之后,在Activity_2上,主页似乎不起作用(当我点击主页按钮时没有任何反应).

    ActionBar bar = this.getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setHomeButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)

如何解决第3步和第4步?

谢谢

android android-sliding android-actionbar

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

如何通过Facebook成功登录后获取用户详细信息

我试过这个:当isSessionValid getDetails直接在facebook.authorize然后在onActivityResult中获取getDetails

public class MainActivity extends Activity {

    Facebook facebook = new Facebook("xxxxxxxxxxxxxxxx");
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    private SharedPreferences mPrefs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mPrefs = getPreferences(MODE_PRIVATE);
        String access_token = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);
        if (access_token != null) {
            facebook.setAccessToken(access_token);
        }
        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }

        if (!facebook.isSessionValid()) {

            facebook.authorize(this, new String[] {}, new DialogListener() {
                @Override
                public void onComplete(Bundle values) {
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token", facebook.getAccessToken());
                    editor.putLong("access_expires",
                            facebook.getAccessExpires()); …
Run Code Online (Sandbox Code Playgroud)

java android facebook

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

仅更改ActionBarSherlock的背景.不是标签

我用这段代码来改变ActionBarSherlock的颜色:

    <style name="Theme.MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">

    <!-- set style for action bar (affects tab bar too) -->
    <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
    <!-- define text style for tabs -->
    <item name="actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
    <item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
</style>

<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">

    <!-- define background for action bar (sets default for all parts of action bar - main, stacked, split) -->
    <item name="android:background">#blue</item>
    <item name="background">#blue</item>
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyleWhite</item>
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyleWhite</item>

    <!-- set background for the tab bar (stacked action bar) - it overrides the background property -->
    <item name="android:backgroundStacked">#grey</item> …
Run Code Online (Sandbox Code Playgroud)

android actionbarsherlock

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

ListView onItemClick无法在Activity中工作

当我在具有ListView的活动中使用它时,它不起作用.

usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            ong arg3) {
    try {
        Intent intent = new Intent(UsersListActivity.this,
                UserActivity.class);
        startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

在寻找解决方案后,我最终getView()适配器中进行了此操作

convertView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            ong arg3) {
    try {
        Intent intent = new Intent(mActivity,
                UserActivity.class);
        mActivity.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

这有效.但为什么这么奇怪的行为.它为什么不按照应有的方式工作.

谢谢

android listview onitemclicklistener

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

为什么新创建的文件夹中的图像不显示?

在我的应用程序中,我可以选择拍照,照片将保存在文件夹中:

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/my-images";
Run Code Online (Sandbox Code Playgroud)

图像保存得很好,我还可以选择使用此代码的图像:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
Run Code Online (Sandbox Code Playgroud)

这里最初用来展示 2 个画廊

1. 相机

2. 我的图片

选择其中任何一个等等,一切都很好。

但我无缘无故地删除了 my-images 文件夹并再次运行了该应用程序。再次创建相同的文件夹,图像按预期保存。

问题是:

我的图片库现在没有显示,当我点击选择图片按钮时。

除了删除 my-images 文件夹并重新启动应用程序外,我没有更改任何代码,因为它曾经运行良好。

为什么会这样?

谢谢

编辑:

我的活动代码,它允许用户拍照并存储在 SD 卡上,并浏览图片库:

public class PictureFromAppActivity extends SherlockActivity {
    private File dir;
    private Bitmap photo;
    private String encodedString;
    private InputStream is;
    private ImageView imagePreview;
    private String selectedImagePath;
    private static final int CAMERA_REQUEST = 1888;
    private static final int SELECT_PICTURE = 1;

    /** Called when the …
Run Code Online (Sandbox Code Playgroud)

camera android image-gallery

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

onBackPress在Fragment中调用了什么

在片段中我有这个:

onPause(){

super.onPause();
if(flag){
getActivity.finish();
}else{
}
}

onResume(){

flag = true;
super.onResume();
}
Run Code Online (Sandbox Code Playgroud)

并且有一个Button,点击我将此标志设置为false:

Button.onClick{
flag = false;
}
Run Code Online (Sandbox Code Playgroud)

这个想法是:

单击按钮时,请勿完成此活动.但是当设备BackButton被按下finish()时.

但这种逻辑不起作用.原因是,当我按下设备的BackButton时,onPause没有被调用.

这是Activty中的第四个片段.因此,当我按BackButton时,我可以看到第3片段.我不想这样做.

我在API 10设备上使用它,但我的应用程序使用支持库v4.

谢谢.

android fragment onresume onpause

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

即使使用最佳提供程序,getLastKnownLocation()也会返回null

这是我用来获取当前位置的代码:

mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
best = mgr.getBestProvider(criteria, true);
if (best == null) {
    //ask user to enable atleast one of the Location Providers
} else {
    Location location = mgr.getLastKnownLocation(best);
//But sometimes it returns null
}
Run Code Online (Sandbox Code Playgroud)

几乎每次都有 best = network

但它有时并没有提供这个位置.

mgr.getLastKnownLocation(best) returns null
Run Code Online (Sandbox Code Playgroud)

也:

onResume() {
    mgr.requestLocationUpdates(best, 15000, 10, this);
}
Run Code Online (Sandbox Code Playgroud)

onPause() {
    mgr.removeUpdates(this);
}
Run Code Online (Sandbox Code Playgroud)

这种情况有替代方案吗?

一种选择可能是

List<String> providers = mgr.getAllProviders();
Run Code Online (Sandbox Code Playgroud)

存储所有提供商并逐步减少1.但从未在任何地方看到过此推荐.此外,要求最好的提供者是文档建议的.

android location locationmanager

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

如何使用颜色代替drawable来切换按钮选择器

<ToggleButton 
        android:id="@+id/toggle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/check"   
        android:layout_margin="10dp"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_centerVertical="true"/>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/selected_image"
          android:state_checked="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/unselected_image"
        android:state_checked="false"/>

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

如何使用颜色代替可绘制颜色

我试过这个:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:color="@color/bg_blue"/>
    <item android:state_checked="false" android:color="@color/bg_light_grey"/>

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

在名称为bg_toggle.xml的颜色文件夹中定义了上述选择器

android:background="@color/bg_toggle"
Run Code Online (Sandbox Code Playgroud)

这给出了一个例外:

android.view.InflateException:二进制XML文件行#50:错误膨胀类android.widget.ToggleButton

org.xmlpull.v1.XmlPullParserException:二进制XML文件行#4:标记需要一个'drawable'属性或定义drawable的子标记

谢谢

xml android selector togglebutton android-layout

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