我正在尝试使用新的通知界面.我已经为通知添加了3个按钮,并且我想在点击每个按钮后将其保存到我的数据库中.
通知本身运行良好,并在调用时显示,我只是不知道如何捕获三个不同的按钮单击中的每一个.
我用a BroadcastReceiver
来捕捉点击,但我不知道如何判断点击了哪个按钮.
这是代码AddAction
(我已经排除了通知的其余部分,因为它运作良好) -
//Yes intent
Intent yesReceive = new Intent();
yesReceive.setAction(CUSTOM_INTENT);
Bundle yesBundle = new Bundle();
yesBundle.putInt("userAnswer", 1);//This is the value I want to pass
yesReceive.putExtras(yesBundle);
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.calendar_v, "Yes", pendingIntentYes);
//Maybe intent
Intent maybeReceive = new Intent();
maybeReceive.setAction(CUSTOM_INTENT);
Bundle maybeBundle = new Bundle();
maybeBundle.putInt("userAnswer", 3);//This is the value I want to pass
maybeReceive.putExtras(maybeBundle);
PendingIntent pendingIntentMaybe = PendingIntent.getBroadcast(this, 12345, maybeReceive, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.calendar_question, "Partly", pendingIntentMaybe);
//No intent
Intent noReceive = …
Run Code Online (Sandbox Code Playgroud) notifications android broadcastreceiver android-intent android-4.0-ice-cream-sandwich
我有一个风格的旋转器.该样式仅包含微调器的背景.问题是,无论我使用哪个图像作为背景,旋转器的文本总是被推到左边.
这是XML中Spinner的声明 -
<Spinner
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/minus"
android:layout_width="wrap_content"
android:layout_below="@+id/female"
android:id="@+id/spin"
android:gravity="center"
android:background="@drawable/spin"
android:layout_marginTop="10dip">
</Spinner>
Run Code Online (Sandbox Code Playgroud)
另外,我在android:gravity属性下得到一个警告,说明它是一个未知的XML属性.
我无法理解为什么会那样做.
谢谢
我正在开发一个小程序,我需要添加一个自定义对话框,在关闭时将一些信息传递给调用活动.我扩展了对话框类,当我尝试在关闭时捕获自定义对话框时,使用onDismiss侦听器,它永远不会到达它,因为我使用了自定义对话框.
这是我活动的一部分 -
.
.
.
attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
customizeDialog.show();
Run Code Online (Sandbox Code Playgroud)
(属性是扩展对话框类的类的名称).
这是我在对话框完成时设置的事件监听器 -
customizeDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Log.v("LOG_CAT",attributes.selectedIndexes.get(0) + " " + attributes.selectedIndexes.get(1) + " " + attributes.selectedIndexes.get(2) + " " + attributes.selectedIndexes.get(3) + " " + attributes.selectedIndexes.get(5) + " ");
}
});
Run Code Online (Sandbox Code Playgroud)
我知道我做错了,我只是不知道如何解决它.
我真的很感激这个问题的任何帮助.
谢谢!
当我试图从Facebook SDK显示墙上发布对话框时,我得到了一个Bad Token Exception(它每2次运行应用程序就会发生).
我有一个"发布"按钮,如果用户登录到他的FB帐户,则显示对话框,或者显示登录对话框(如果用户不是,则显示"在墙上发布"对话框)登录到他的帐户.
这是发布按钮的点击监听器 -
mPostButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(mLoginButton.getVisibility() == 0)
postOnWall();
else
mLoginButton.performClick();
}
});
Run Code Online (Sandbox Code Playgroud)
这是onAuthSucceed()监听器 -
public void onAuthSucceed() {
postOnWall();
}
Run Code Online (Sandbox Code Playgroud)
这是PostOnWall函数(显示发布对话框) -
public void postOnWall()
{
Bundle params = new Bundle();
params.putString("name", FBname);
params.putString("link", FBlink);
params.putString("description", FBdescription);
params.putString("picture", FBpicture);
con = this;
mFacebook.dialog(con, "feed", params, new SampleDialogListener());
}
Run Code Online (Sandbox Code Playgroud)
这是错误的日志 -
05-05 16:25:09.601: WARN/WindowManager(109): Attempted to add application window with unknown token HistoryRecord{405416b0 android.alco/.do_drive}. Aborting.
05-05 16:25:27.292: ERROR/AndroidRuntime(20089): android.view.WindowManager$BadTokenException: Unable …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个Android应用程序.
我今天在我的应用程序上工作,突然间我看到工作区中的所有项目都标有错误.我不知道是什么造成的,我无法在任何地方找到错误的解释.
我在Windows 7上使用Helios.我甚至尝试再次下载Eclipse,但它没有帮助.
今天我尝试将Facebook与我的应用程序集成.他们的教程要求我尝试从密钥库中获取一个hesh密钥.在这个过程中,我添加了一个名为JAVA_HOME的环境变量,并将其指向JDK.
我不知道这是否是我问题的原因,但我认为这可能是相关的.
我真的不知道该怎么办.
谢谢!
我正在尝试绑定服务,但onBind()
总是返回false.
这是 - 的代码ServiceConnection
-
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with our service has been established,
// giving us the service object we can use to interact with our service.
mBoundService = ((ScheduleService.ServiceBinder) service).getService();
}
public void onServiceDisconnected(ComponentName className) {
mBoundService = null;
}
};
Run Code Online (Sandbox Code Playgroud)
这是对bindService()
-
boolean test = getApplicationContext().bindService(new Intent(this, ScheduleService.class), mConnection, Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)
这是清单中服务的声明 -
<service android:name=".Notifications.ScheduleService" android:enabled="true"/> …
Run Code Online (Sandbox Code Playgroud) service notifications android android-service android-context
我正在构建一个Android应用程序,我有一个非常愚蠢的问题 -
我已经创建了一个首选项屏幕,并在其中放入一个列表和一个复选框.现在我使用自动保存的'key'属性来处理这些问题.
当我尝试使用一个简单的首选项时,我的问题出现了(他们输入你只是按它).SharedPreference
单击时保存的内容是什么?如果没有,我怎么能抓住点击事件?
我无法在任何地方找到答案.非常感谢!
我在我的应用中添加了一个功能,可以打开联系人列表.问题是有些用户报告说应用程序在尝试使用时崩溃了.该功能似乎适用于大多数人(包括Nexus S).
这是我用来打开联系人的代码 -
call_friend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent();
i.setComponent(new ComponentName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity"));
i.setAction("android.intent.action.MAIN");
i.addCategory("android.intent.category.LAUNCHER");
i.addCategory("android.intent.category.DEFAULT");
startActivity(i);
}
});
Run Code Online (Sandbox Code Playgroud)
这是崩溃的日志 -
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.contacts/com.android.contacts.DialtactsContactsEntryActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
at android.app.Activity.startActivityForResult(Activity.java:2817)
at android.app.Activity.startActivity(Activity.java:2923)
at can.you.drive.dont_drive$1.onClick(dont_drive.java:75)
at android.view.View.performClick(View.java:2465)
at android.view.View$PerformClick.run(View.java:8907)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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 dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我不知道是什么导致了它.谢谢!
我是SQL的新手,我正在尝试使用Android应用程序中的简单数学进行查询.这就是我要做的 -
我有一个名为allfoods的表,名为'calories'和'size'的列.这是查询 -
int tempCalories = 100;
int maxCalories = 300;
Cursor dataFoods = myDataBase.rawQuery("SELECT id FROM allfoods WHERE size <> 0 AND (" + tempCalories + " + (calories * (size / 100)) < " + maxCalories +")" , null);
Run Code Online (Sandbox Code Playgroud)
那会有用吗?我自己测试它有些麻烦,因为返回的值太多了.
谢谢!
嘿,我正在构建一个包含数据库的Android应用程序.我的问题是如何知道应用程序是否已更新?我的意思是,我知道当DATABASE_VERSION来自 - 时调用onUpgrade方法 -
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
this.myContext = context;
}
Run Code Online (Sandbox Code Playgroud)
低于应用程序的版本,但如何在更新后增加它,因此应用程序不会一直更新自己?
android ×10
java ×3
sqlite ×2
android-4.0-ice-cream-sandwich ×1
dialog ×1
eclipse ×1
facebook ×1
preferences ×1
service ×1
sql ×1