我的应用程序搜索新文章并发送“5 篇新文章”之类的通知。但是,当我发送另一篇文章时,我想让它更新文本,让我们说有 3 篇新文章,例如“8 篇新文章”,但如果用户已取消之前的通知,则为“3 篇新文章”。我希望你能明白。
有没有办法知道通知已被取消,以便我可以重置计数?
谢谢 !
我正在尝试在我的应用程序中实现共享一个简单的字符串.显然Facebook以外的一切都有效.据我所知,现在我必须使用他们的Facebook SDK在墙上发布状态.
但是,如果我使用他们的SDK实现它,有没有办法将它合并到选择器(默认或ShareActionProvider)并以某种方式覆盖它并插入Facebook SDK的实现?
或者我必须创建一个专用按钮?
//编辑
package com.example.shareactionproviderdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test message");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
}
Run Code Online (Sandbox Code Playgroud)

我是Rails的新手所以请耐心等待.
我想在我的食堂模型上实现"喜欢",所以我在我的食堂资源中创建了一个自定义路线
resources :canteens do
resources :meals
resources :comments
match "/like", :to => "canteens#like", :as => "like"
end
Run Code Online (Sandbox Code Playgroud)
因此在canteens控制器中创建了这个动作,我只是增加一个计数器
def like
canteen = Canteen.find(params[:canteen_id])
Canteen.increment_counter("likes_count", canteen.id)
redirect_to canteen
end
Run Code Online (Sandbox Code Playgroud)
所以,手动输入URL localhost:3000/canteens/1/like工作得很好,但显然我想创建一个按钮,所以我做了一个
<h2>Likes count</h2>
<p><%= @canteen.likes_count %> likes</p>
<p><%= link_to "Like this canteen", canteen_like_path %></p>
Run Code Online (Sandbox Code Playgroud)
它不起作用.我检查了耙路线,它就在那里(canteen_like).我究竟做错了什么?
我有一个ViewHolder订阅了 Rx Observable。现在我需要处理一次性用品,所以我这样做了,onViewRecycled()因为我读过它应该是为了释放资源,但是它永远不会被调用,甚至轮换也不被调用。这是预期的行为吗?
可能是因为我的项目很少,5 个由 3 个视图类型组成?onDetachedFromRecyclerView被调用,但我想在构造函数中订阅,而不是每次它回到屏幕/屏幕外时
public class FeedAdapter {
onCreateViewHolder ..
onBindViewHolder..
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
// THIS IS WHAT I HAVE NEVER SEEN GET CALLED
if (holder instanceof FeaturedBooksHolder) {
((FeaturedBooksHolder) holder).dispose();
}
}
static class FeaturedBooksHolder extends BooksHolder {
private final Disposable mDisposable;
FeaturedBooksHolder(View itemView, OnBookClickListener listener, AdapterClickListener headerClickListener, Observable<Tuple2<Boolean, NativeAdsManager>> observable) {
super(itemView, listener, headerClickListener);
mRecyclerView = findById(itemView, recyclerView);
BooksAdapter adapter …Run Code Online (Sandbox Code Playgroud) 我需要查询方面的帮助。我有多个食堂,每个食堂有多个餐点,每餐有多个 MealPicks。
虽然我不知道这个MealPick模型是否是个好主意,因为我需要显示今天这顿饭被挑选了多少次,所以我需要时间戳来进行这个查询。
class Meal < ActiveRecord::Base
def todays_picks
meal_picks.where(["created_at >= ? AND created_at < ?", Date.today.beginning_of_day, Date.today.end_of_day])
end
end
Run Code Online (Sandbox Code Playgroud)
在我在 Meal 中只有一个 meal_picked_count 计数器之前,我通过 increment_counter 方法增加了它。
好的,现在我需要为每个 Canteen 显示 MealPicks 最多的 Meal,我在控制台中玩弄并尝试了类似的东西,Canteen.find(1).meals.maximum("meal_picks.count")但这显然不起作用,因为它不是一个列。
有任何想法吗?
我试图在首选项中设置对话框首选项,用户只需单击"正向"按钮即可触发某些操作.(清除数据库?否|是)
public class MyDialogPreference extends DialogPreference {
public MyDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
Log.d(MainActivity.TAG, "# onDialogClosed: " + positiveResult);
}
}
Run Code Online (Sandbox Code Playgroud)
我实际上并不想坚持任何东西,只是触发onSharedPreferenceChanged监听器,所以我可以在活动中处理它.但我无法弄清楚如何触发它
//解
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if(positiveResult) {
persistBoolean(!getPersistedBoolean(true));
}
Log.d(MainActivity.TAG, "# onDialogClosed: " + positiveResult);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Conductor(或任何自定义类)进行dagger-android工作.我尝试复制AndroidSupportInjectionModule(和朋友)所做的一切,在我看来,这是一种自定义类处理.
但是我得到了
C:\Users\ursus\AndroidStudioProjects\...\ControllersModule.java:15: error: com.foo.bar.ChannelsController is not a framework type
public abstract com.foo.bar.ChannelsController channelsController();
Run Code Online (Sandbox Code Playgroud)
所以,我的"库"代码
package com.foo.bar
import com.bluelinelabs.conductor.Controller;
import dagger.Module;
import dagger.android.AndroidInjectionModule;
import dagger.android.AndroidInjector;
import dagger.internal.Beta;
import dagger.multibindings.Multibinds;
import java.util.Map;
@Beta
@Module(includes = AndroidInjectionModule.class)
public abstract class ConductorInjectionModule {
private ConductorInjectionModule() {
}
@Multibinds
abstract Map<Class<? extends Controller>, AndroidInjector.Factory<? extends Controller>> controllerInjectorFactories();
@Multibinds
abstract Map<String, AndroidInjector.Factory<? extends Controller>> controllerInjectorFactoriesWithStringKeys();
}
Run Code Online (Sandbox Code Playgroud)
我甚至没有编译,所以假设粘贴ConductorInjection和HasControllerInjector毫无意义
用法:
@Module
abstract class AppModule {
@ContributesAndroidInjector abstract fun mainActivity(): MainActivity
@ContributesAndroidInjector abstract fun channelsController(): ChannelsController
}
class …Run Code Online (Sandbox Code Playgroud) 我正在尝试1.1.0-beta1中新的屏障功能.它按预期工作,但有这个用例我似乎无法计算或(或者可能是ConstraintLayout?)
我想要完成的是:我在左侧有一个图像视图,在图像视图右侧有标题和副标题文本视图.Imageview是固定的高度.我有一个按钮,底部约束到图像视图的底部, 但是如果subtitletextview比imageview高,则应该顶部约束到字幕文本视图的底部.
(顺便说一下,我也尝试将它的底部约束到imageview的底部,并将topconstrained到textview的底部并向底部赋予1.0偏向,但是对于大文本情况不起作用)
有障碍我只能将按钮顶部限制在障碍物的底部(或顶部,似乎相同)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@color/blue"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:scaleType="centerCrop"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/books"/>
<ImageView
android:id="@+id/imageView6"
android:layout_width="124dp"
android:layout_height="156dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4"
app:srcCompat="@android:drawable/radiobutton_on_background"/>
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/imageView6"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4"/>
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Lorem Ipsum je fiktívny text, používaný pri návrhu tla?ovín a typografie. Lorem Ipsum je štandardným výpl?ovým textom už od …Run Code Online (Sandbox Code Playgroud) 我有这个现实世界的场景。
我有一个 ReaderConfig 对象,它是 ReaderTheme、ReaderFont、ReaderFontSize 的哑元组。它的更改将触发 readerConfigObservable,然后重新绘制内容。
所以到目前为止的解决方案是
combineLatest(themeObservable, fontObservable, fontSizeObservable,
(theme, font, fontSize) -> new ReaderConfig(theme, font, fontSize))
Run Code Online (Sandbox Code Playgroud)
然而,因为这是android,ReaderTheme设置了一些android R.theme。东西,需要重新启动 Activity 才能生效。所以我还需要自行公开 themeObservable
themeObservable.subscribe(__ -> activity.recreate())
Run Code Online (Sandbox Code Playgroud)
由于它重新启动了 Activity,因此不需要触发 mergeLatest,它会触发重绘并分配资源,只是因为重新启动而在 1 秒后被处理掉。
因此,只有 fontObservable 和 fontSizeObservable 更改应该触发 mergeLatest,但是我确实需要最新的 themeObservable 值才能构造 ReaderConfig 对象。
我的解决方法是这样的
public Observable<ReaderConfig> readerConfigObservable() {
return Observable.combineLatest(
mFontRelay, mFontSizeRelay, (__, ___) -> createReaderConfig());
}
public ReaderConfig createReaderConfig() {
return new ReaderConfig(mThemeRelay.getValue(), mFontRelay.getValue(), mFontSizeRelay.getValue());
}
Run Code Online (Sandbox Code Playgroud)
所以基本上它在组合器函数中提取了themeObservable ,这并不是真正的反应性,对于这个异常用例有没有合适的解决方案?
有 swiftui 失效专家吗?
我知道视图结构初始值设定项应该一直被调用,但只有当输入更改时才调用主体= swiftui 优化
struct FooView : View {
let counter: Int
let onOpenFaq: () -> Void
@State showDialog = false
var body: some View {
...
.sheet(isPresented: $showDialog) {
SimpleSheetContent(
title: "Bar",
message: "Bar messagge",
onPositiveClick: onOpenFaq,
onNegativeClick: {
showDialog = false <------------------
}
)
}
}
}
struct SimpleSheetContent : View {
let title: String
let message: String
let onPositiveClick: () -> Void
let onNegativeClick: () -> Void
var body: some View {
let _ = …Run Code Online (Sandbox Code Playgroud)