小编Ric*_*ler的帖子

在Manifest中注册应用程序类?

我有一个Application类来保持我的应用程序的全局状态.但是我无法在Manifest文件中注册它?知道怎么做吗?

android android-manifest

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

Android弹出窗口被解雇

当我单击列表活动中的项目时,我会显示一个弹出窗口.问题是后退键不会关闭它.我尝试在列表活动中捕获后退键但它没有注册它...然后我尝试将onkeylistener注册到我正在传递到弹出窗口的视图中.像这样:

pop.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            boolean res=false;
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                // do something on back.
                Log.e("keydown","back");
                if (pw.isShowing()) {
                    Log.e("keydown","pw showing");
                    pw.dismiss();
                    res = true;
                }
            } else {
                res = false;
            }
            return res;
        }
    });
Run Code Online (Sandbox Code Playgroud)

传递给像这样的弹出窗口:

pw = new PopupWindow(
       pop, 
       240, 
       70, 
       true);
Run Code Online (Sandbox Code Playgroud)

但那个听众既不会开火也不会开火.你能帮助我吗?我没有想法:)

android popupwindow

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

Android如何等待服务实际连接?

我有一个Activity调用在IDownloaderService.aidl中定义的服务:

public class Downloader extends Activity {
 IDownloaderService downloader = null;
// ...
Run Code Online (Sandbox Code Playgroud)

在Downloader.onCreate(Bundle)中,我尝试使用bindService

Intent serviceIntent = new Intent(this, DownloaderService.class);
if (bindService(serviceIntent, sc, BIND_AUTO_CREATE)) {
  // ...
Run Code Online (Sandbox Code Playgroud)

在ServiceConnection对象sc中,我做到了这一点

public void onServiceConnected(ComponentName name, IBinder service) {
  Log.w("XXX", "onServiceConnected");
  downloader = IDownloaderService.Stub.asInterface(service);
  // ...
Run Code Online (Sandbox Code Playgroud)

通过添加各种Log.xx,我发现if(bindService(...))之后的代码实际上是在调用ServiceConnection.onServiceConnected之前 - 也就是说,当下载器仍然为null时 - 这让我遇到了麻烦.ApiDemos中的所有样本都通过仅在用户操作触发时调用服务来避免此时间问题.但是,在bindService成功之后,我该怎么做才能正确使用这个服务?如何可靠地等待ServiceConnection.onServiceConnected被调用?

另一个问题有关.是所有的事件处理程序:Activity.onCreate,任何View.onClickListener.onClick,ServiceConnection.onServiceConnected等实际在同一个线程中调用(在文档中提到的"主线程")?它们之间是否存在交错,或Android会安排所有事件逐个处理?或者,究竟什么时候实际上要调用ServiceConnection.onServiceConnected?完成Activity.onCreate或A.oC仍在运行时?

service binding android serviceconnection

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

如何在Android上制作Twitter应用程序风格的快速操作

是否有任何代码可以提供有关如何实现Twitter for Android应用程序中显示的"快速操作"和"弹出"菜单的示例?

user-controls android popupwindow android-view

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

将Object作为下一个活动的意图

是否可以将Object类型的对象作为Extra添加到intent中?我有一个类型为object的变量,直到为它分配了一个关于对象数据类型的值才会知道.也许与序列化有关或作为一个捆绑我不确定?然后在下一个活动中,如何获取此值以将其存储在ArrayList<Object>

android bundle object parcelable android-intent

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

Android:IllegalStateException - 什么时候抛出?

在我的应用程序中,有时抛出以下异常:

07-28 14:49:25.398: ERROR/AndroidRuntime(8097):
java.lang.IllegalStateException: The content of the adapter has changed
but ListView did not receive a notification. Make sure the content of
your adapter is not modified from a background thread, but only from the
UI thread. [in ListView(2131099717, class android.widget.ListView) with
Adapter(class ch.uzh.csg.games4blue.gamebase.view.UserView$UserAdapter)]
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.widget.ListView.layoutChildren(ListView.java:1432)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.widget.AbsListView.onLayout(AbsListView.java:1113)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.view.View.layout(View.java:6831)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at
android.widget.LinearLayout.onLayout(LinearLayout.java:918)
07-28 14:49:25.398: ERROR/AndroidRuntime(8097):     at …
Run Code Online (Sandbox Code Playgroud)

java layout user-interface android listview

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

Android 5.0 Lollipop:setColorFilter"泄漏"到其他按钮上

setColorFilter用来设置我的一个按钮的彩色滤镜.这一直在Android 5.0 Lollipop更新之前完美运行.现在,滤色器似乎泄漏到我的其他按钮上,即使我关闭活动并重新打开(如果我关闭应用程序并重新打开它会重置).

我的styles.xml(v21):(与旧的相同,除了它的父级是Material,之前是Holo)

<style name="Theme.FullScreen" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
    <item name="android:buttonStyle">@style/StandardButton</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的styles.xml(适用于所有版本):

<style name="StandardButton" parent="android:style/Widget.Button">
    <item name="android:background">@android:drawable/btn_default</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的按钮:

<Button
    android:id="@+id/mainMenuButton"              
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="mainMenu"
    android:text="@string/button_mainMenu"
    android:visibility="gone" />
Run Code Online (Sandbox Code Playgroud)

我的代码:

Button mainMenuButton = (Button) findViewById(R.id.mainMenuButton);
mainMenuButton.getBackground().setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.light_green), PorterDuff.Mode.MULTIPLY));
mainMenuButton.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)

颜色:

<color name="light_green">#5CD65C</color>
Run Code Online (Sandbox Code Playgroud)

结果:

我打开应用程序,然后游戏活动和所有按钮都正确显示.我按下按钮设置滤色器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色.

有任何想法吗?

android android-layout android-styles android-5.0-lollipop

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

实现OnClickListener VS. new Button.OnClickListener(){};

我有一个关于实现OnClickListeners以使用ADT进行开发的问题.我不确定哪种方式更有效率,任何人都可以请我提供每种方法的专业知识吗?

class x extends Activity implements OnClickListener
{
  button.SetOnClickListener(this);
  OnclickListener(View v)
  {
    switch(v.getGetId());
    {
      case R.id.y:
      //do stuff here
      break;
      .
      .
      .
    }
  }

}
Run Code Online (Sandbox Code Playgroud)

<-VERSUS->

class a extends Activity
{
   .
   .
   .
   btn.setOnClickListener(new Button.OnClickListener()
   {

    OnClickListener(View v)
    {
      //do stuff here
    }

   });

}
Run Code Online (Sandbox Code Playgroud)

java android

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

从广播接收器获取唤醒锁定的问题

我有个问题.我正在尝试让广播接收器获得唤醒锁定,以便我的闹钟将手机从睡眠模式唤醒.

在下面的广播接收器中,程序在"scpuWakeLock.acquire()"行上遇到"source not found"崩溃;当AlarmReceiver调用类"AlarmAlertWakeLock"时.知道发生了什么吗?有没有更好的方法来做我的事情我想干什么?

在一个文件中:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        AlarmAlertWakeLock.acquireCpuWakeLock(context);

    }    
}
Run Code Online (Sandbox Code Playgroud)

在单独的文件中:

import android.content.Context;
import android.os.PowerManager;

public class AlarmAlertWakeLock {

    private static PowerManager.WakeLock sCpuWakeLock;

    static void acquireCpuWakeLock(Context context) {

        if (sCpuWakeLock != null) {
            return;
        }
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);


        sCpuWakeLock = pm.newWakeLock(
                PowerManager.PARTIAL_WAKE_LOCK |
                PowerManager.ACQUIRE_CAUSES_WAKEUP,"okTag");
        sCpuWakeLock.acquire();
    }

    static void releaseCpuLock() {
        if (sCpuWakeLock != null) {
            sCpuWakeLock.release();
            sCpuWakeLock = null; …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver alarm

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

AlertDialog.Builder:没有显示复选框的项目

我在以下代码中遇到了alertdialog.builder的问题:

    public void showSettingsBox(){
  final CharSequence[] items = {"Item1", "Item2", "Item3"};
  final boolean checked[] = new boolean[]{false,false,false};

  AlertDialog.Builder builder = new AlertDialog.Builder(fLabyrinthGame); 
  builder.setMessage(fMessage)
   .setCancelable(false)
   .setMultiChoiceItems(items, checked, new OnMultiChoiceClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
     CharSequence text = "Item number " + which;
     int duration = Toast.LENGTH_SHORT;

     Toast toast = Toast.makeText(fLabyrinthGame, text, duration);
     toast.show();

    }
   })
   .setPositiveButton("Apply", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
     dialog.cancel();
    }
   });
  builder.setTitle(fTitle); 
  builder.setIcon(R.drawable.icon_exclamation); 

  AlertDialog alert = builder.create(); …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog

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