Check if List startsWith another String using Stream.of
I have List witch contain two different url
my urls :
https://is2-ssl.mzstatic.com/image/thumb/Music111/v4/31/5b/62/315b62fb-3b46-d2ee-5833-be210d3287f7/source/100x100bb.jpg
and
https://lastfm-img2.akamaized.net/i/u/300x300/5ed371a8b6d03258d597eb661805baee.png
I would like to switch icon image in my AdaperRecyclerView (comparing the beginning of a url) , but my loop dont work like I would like.
my code for switch image:
@Override
public void onBindViewHolder(@NonNull SongHolder holder, int possition)
// Source image swicher
holder.binding.setModelItem(localArtistNameList.get(possition));
if( Stream.of(localSourceList).anyMatch((s) -> s.startsWith("https://is")))
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_itune);
else
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
@Override
public int getItemCount()
return localArtistNameList.size();
my issue is that icon cannot change. I debag it and for and for simplicity I did print screen:

java
add a comment |
I have List witch contain two different url
my urls :
https://is2-ssl.mzstatic.com/image/thumb/Music111/v4/31/5b/62/315b62fb-3b46-d2ee-5833-be210d3287f7/source/100x100bb.jpg
and
https://lastfm-img2.akamaized.net/i/u/300x300/5ed371a8b6d03258d597eb661805baee.png
I would like to switch icon image in my AdaperRecyclerView (comparing the beginning of a url) , but my loop dont work like I would like.
my code for switch image:
@Override
public void onBindViewHolder(@NonNull SongHolder holder, int possition)
// Source image swicher
holder.binding.setModelItem(localArtistNameList.get(possition));
if( Stream.of(localSourceList).anyMatch((s) -> s.startsWith("https://is")))
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_itune);
else
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
@Override
public int getItemCount()
return localArtistNameList.size();
my issue is that icon cannot change. I debag it and for and for simplicity I did print screen:

java
add a comment |
I have List witch contain two different url
my urls :
https://is2-ssl.mzstatic.com/image/thumb/Music111/v4/31/5b/62/315b62fb-3b46-d2ee-5833-be210d3287f7/source/100x100bb.jpg
and
https://lastfm-img2.akamaized.net/i/u/300x300/5ed371a8b6d03258d597eb661805baee.png
I would like to switch icon image in my AdaperRecyclerView (comparing the beginning of a url) , but my loop dont work like I would like.
my code for switch image:
@Override
public void onBindViewHolder(@NonNull SongHolder holder, int possition)
// Source image swicher
holder.binding.setModelItem(localArtistNameList.get(possition));
if( Stream.of(localSourceList).anyMatch((s) -> s.startsWith("https://is")))
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_itune);
else
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
@Override
public int getItemCount()
return localArtistNameList.size();
my issue is that icon cannot change. I debag it and for and for simplicity I did print screen:

java
I have List witch contain two different url
my urls :
https://is2-ssl.mzstatic.com/image/thumb/Music111/v4/31/5b/62/315b62fb-3b46-d2ee-5833-be210d3287f7/source/100x100bb.jpg
and
https://lastfm-img2.akamaized.net/i/u/300x300/5ed371a8b6d03258d597eb661805baee.png
I would like to switch icon image in my AdaperRecyclerView (comparing the beginning of a url) , but my loop dont work like I would like.
my code for switch image:
@Override
public void onBindViewHolder(@NonNull SongHolder holder, int possition)
// Source image swicher
holder.binding.setModelItem(localArtistNameList.get(possition));
if( Stream.of(localSourceList).anyMatch((s) -> s.startsWith("https://is")))
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_itune);
else
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
@Override
public int getItemCount()
return localArtistNameList.size();
my issue is that icon cannot change. I debag it and for and for simplicity I did print screen:

java
java
asked Nov 13 '18 at 10:59
htw htw
70719
70719
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use this code in onBindViewHolder:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279534%2fcheck-if-liststring-startswith-another-string-using-stream-of%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use this code in onBindViewHolder:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
add a comment |
Use this code in onBindViewHolder:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
add a comment |
Use this code in onBindViewHolder:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
Use this code in onBindViewHolder:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();
answered Nov 13 '18 at 11:47
OnixOnix
4478
4478
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
add a comment |
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
I will change my code, your code is more elegant, get(possition) fix issue.
– htw
Nov 13 '18 at 12:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279534%2fcheck-if-liststring-startswith-another-string-using-stream-of%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown