我试图将一些for-each循环更改为lambda forEach()
-methods以发现lambda表达式的可能性.以下似乎是可能的:
ArrayList<Player> playersOfTeam = new ArrayList<Player>();
for (Player player : players) {
if (player.getTeam().equals(teamName)) {
playersOfTeam.add(player);
}
}
Run Code Online (Sandbox Code Playgroud)
随着lambda forEach()
players.forEach(player->{if (player.getTeam().equals(teamName)) {playersOfTeam.add(player);}});
Run Code Online (Sandbox Code Playgroud)
但下一个工作不起作用:
for (Player player : players) {
if (player.getName().contains(name)) {
return player;
}
}
Run Code Online (Sandbox Code Playgroud)
与lambda
players.forEach(player->{if (player.getName().contains(name)) {return player;}});
Run Code Online (Sandbox Code Playgroud)
最后一行的语法有问题还是不可能从forEach()
方法返回?
我有一个ViewPager
内部ScrollView
.我需要能够水平滚动和垂直滚动.为了实现这一点,每当我ViewPager
被触摸(v.getParent().requestDisallowInterceptTouchEvent(true);
)时都必须禁用垂直滚动,以便它可以水平滚动.
但与此同时,我需要能够单击viewPager以全屏模式打开它.
问题是在onClick之前调用onTouch并且从不调用我的OnClick.
如何实现触摸onClick?
viewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println("TOUCHED ");
if(event.getAction() == MotionEvent.???){
//open fullscreen activity
}
v.getParent().requestDisallowInterceptTouchEvent(true); //This cannot be removed
return false;
}
});
viewPager.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("CLICKED ");
Intent fullPhotoIntent = new Intent(context, FullPhotoActivity.class);
fullPhotoIntent.putStringArrayListExtra("imageUrls", imageUrls);
startActivity(fullPhotoIntent);
}
});
Run Code Online (Sandbox Code Playgroud) 我使用以下代码来获取google plus的访问令牌.有没有办法获取刷新令牌,以便我可以从Web服务器脱机访问谷歌API.
String accountName = params[0];
String scopes = "oauth2:profile email";
String token = null;
try {
token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
Log.e(TAG, e.getMessage());
}
Run Code Online (Sandbox Code Playgroud) 我有一个场景,我必须保持引用计数对象的给定键ConcurrentDictionary
,如果引用计数达到0
,我想删除键.这必须是线程安全的,因此我打算使用ConcurrentDictionary
.
示例程序如下.在并发字典中,我有键和值,值是KeyValuePair,它保存我的自定义对象和引用计数.
ConcurrentDictionary<string, KeyValuePair<object, int>> ccd =
new ConcurrentDictionary<string, KeyValuePair<object, int>>();
// following code adds the key, if not exists with reference
// count for my custom object to 1
// if the key already exists it increments the reference count
var addOrUpdateValue = ccd.AddOrUpdate("mykey",
new KeyValuePair<object, int>(new object(), 1),
(k, pair) => new KeyValuePair<object, int>(pair.Key, pair.Value + 1));
Run Code Online (Sandbox Code Playgroud)
现在我想要一种方法来在引用计数达到0时删除密钥.我在想,删除带有ConcurrentDictionary
键和谓词的方法,如果谓词返回'true'则删除密钥.例.
ConcurrentDictionary.remove(TKey, Predicate<TValue> ).
Run Code Online (Sandbox Code Playgroud)
没有这样的方法ConcurrentDictionary
,问题是如何以线程安全的方式做同样的事情?
.net c# multithreading task-parallel-library concurrentdictionary
我正在做的是这个
Button button1 = FindViewById<Button>(Resource.Id.button1);
button1.SetOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Perform action on click
}
});
Run Code Online (Sandbox Code Playgroud)
但由于某些原因,我OnClickListener
用红色加下划线.当我点击我的按钮时,我无法执行任何操作来启动功能.
我正在开发Android应用程序,并null
在使用时回来查看IMEI号码TelophonyManager
.这在几部华为手机上都有发生.(所有这些都是Ascend Y530s).
手机都有SIM卡,否则看起来运行正常.我的印象是只有破损的手机会返回null
IMEI.显然情况并非如此......
问题.这个IMEI号究竟是什么 - 即它存储在设备上的哪个位置?当看似精美的手机恢复其价值时,它意味着什么null
?
编辑
我应该提到IMEI号并不总是如此null
.大概有一半的时间似乎是有效的(虽然这很难衡量,因为我们有5部电话有时返回空的IMEI号码\ )
在GCM 3.0
应用程序处于后台时的通知中将自行处理GCM SDK
.但是我无法将应用程序处于后台时创建的通知设置为大图标.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}
Run Code Online (Sandbox Code Playgroud)
该myicon
送到这里显示为小图标.
当应用程序处于后台时,是否可以设置大图标以进行通知?
我们在Android应用程序中添加了crashlytics,我们正在使用proguard
.因此,正如crashlytics
文档所述,我们在proguard
配置文件中添加了以下代码:
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keepattributes SourceFile,LineNumberTable *Annotation*
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我们签署APK时,我们收到以下错误:
java.io.IOException: proguard.ParseException: Unknown option '*Annotation*'
Run Code Online (Sandbox Code Playgroud)
我们做错了什么?
提前致谢
android proguard crashlytics android-proguard crashlytics-android
android ×7
java ×3
c# ×2
.net ×1
atom-editor ×1
crashlytics ×1
foreach ×1
google-plus ×1
imei ×1
java-8 ×1
lambda ×1
proguard ×1
qr-code ×1
return-type ×1
sublimetext ×1
xamarin ×1
zxing ×1