Android array check values using if statement inside ListView onItemClickHow do I determine whether an array contains a particular value in Java?How do I check if an array includes an object in JavaScript?How do you check if a variable is an array in JavaScript?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueDetermine whether an array contains a valueCheck if a value exists in an array in RubyHow to check if an object is an array?Copy array by valueRemove duplicate values from JS arrayI want to display image from internet from main activity to another activity?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

Collect Fourier series terms

Why is consensus so controversial in Britain?

What do three bars across the stem of a note mean?

Is it unprofessional to ask if a job posting on GlassDoor is real?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

What defenses are there against being summoned by the Gate spell?

tikz: show 0 at the axis origin

How does one intimidate enemies without having the capacity for violence?

Why was the small council so happy for Tyrion to become the Master of Coin?

How to write a macro that is braces sensitive?

What is the offset in a seaplane's hull?

I'm planning on buying a laser printer but concerned about the life cycle of toner in the machine

Why Is Death Allowed In the Matrix?

Is it important to consider tone, melody, and musical form while writing a song?

How is it possible to have an ability score that is less than 3?

TGV timetables / schedules?

Why not use SQL instead of GraphQL?

Which models of the Boeing 737 are still in production?

What typically incentivizes a professor to change jobs to a lower ranking university?

Test if tikzmark exists on same page

Can I ask the recruiters in my resume to put the reason why I am rejected?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Can I make popcorn with any corn?



Android array check values using if statement inside ListView onItemClick


How do I determine whether an array contains a particular value in Java?How do I check if an array includes an object in JavaScript?How do you check if a variable is an array in JavaScript?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueDetermine whether an array contains a valueCheck if a value exists in an array in RubyHow to check if an object is an array?Copy array by valueRemove duplicate values from JS arrayI want to display image from internet from main activity to another activity?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have some values in my array and I want to check them using if statement if it's correct to intent its new activity.




Note: I don't need to use the position




 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 

String[] products= "Acer", "HP", "Lenova";

if (products.toString().equals("HP"))
startActivity(new Intent(this, hpcomputer.class));

//Others Conditions










share|improve this question
























  • Try editing your question. How do you want to "check them"? What do you mean?

    – Taslim Oseni
    Mar 21 at 22:45











  • Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

    – Themelis
    Mar 21 at 22:48











  • i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

    – Jimale Abdi
    Mar 21 at 22:51











  • stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

    – bk7
    Mar 22 at 5:12











  • Thank you @bk7 not works for me

    – Jimale Abdi
    Mar 22 at 10:55

















2















I have some values in my array and I want to check them using if statement if it's correct to intent its new activity.




Note: I don't need to use the position




 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 

String[] products= "Acer", "HP", "Lenova";

if (products.toString().equals("HP"))
startActivity(new Intent(this, hpcomputer.class));

//Others Conditions










share|improve this question
























  • Try editing your question. How do you want to "check them"? What do you mean?

    – Taslim Oseni
    Mar 21 at 22:45











  • Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

    – Themelis
    Mar 21 at 22:48











  • i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

    – Jimale Abdi
    Mar 21 at 22:51











  • stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

    – bk7
    Mar 22 at 5:12











  • Thank you @bk7 not works for me

    – Jimale Abdi
    Mar 22 at 10:55













2












2








2


0






I have some values in my array and I want to check them using if statement if it's correct to intent its new activity.




Note: I don't need to use the position




 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 

String[] products= "Acer", "HP", "Lenova";

if (products.toString().equals("HP"))
startActivity(new Intent(this, hpcomputer.class));

//Others Conditions










share|improve this question
















I have some values in my array and I want to check them using if statement if it's correct to intent its new activity.




Note: I don't need to use the position




 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 

String[] products= "Acer", "HP", "Lenova";

if (products.toString().equals("HP"))
startActivity(new Intent(this, hpcomputer.class));

//Others Conditions







java android arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 23:16









Yaroslav Ovdiienko

385318




385318










asked Mar 21 at 22:37









Jimale AbdiJimale Abdi

1089




1089












  • Try editing your question. How do you want to "check them"? What do you mean?

    – Taslim Oseni
    Mar 21 at 22:45











  • Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

    – Themelis
    Mar 21 at 22:48











  • i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

    – Jimale Abdi
    Mar 21 at 22:51











  • stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

    – bk7
    Mar 22 at 5:12











  • Thank you @bk7 not works for me

    – Jimale Abdi
    Mar 22 at 10:55

















  • Try editing your question. How do you want to "check them"? What do you mean?

    – Taslim Oseni
    Mar 21 at 22:45











  • Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

    – Themelis
    Mar 21 at 22:48











  • i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

    – Jimale Abdi
    Mar 21 at 22:51











  • stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

    – bk7
    Mar 22 at 5:12











  • Thank you @bk7 not works for me

    – Jimale Abdi
    Mar 22 at 10:55
















Try editing your question. How do you want to "check them"? What do you mean?

– Taslim Oseni
Mar 21 at 22:45





Try editing your question. How do you want to "check them"? What do you mean?

– Taslim Oseni
Mar 21 at 22:45













Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

– Themelis
Mar 21 at 22:48





Because the elements of the products are Strings products.equals("HP") is fine, but also what you wrote is correct.

– Themelis
Mar 21 at 22:48













i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

– Jimale Abdi
Mar 21 at 22:51





i have listview values Acer, HP, Lenova, so i need if i click HP to intent it hpcomputer activity with out using index i need to use the string values

– Jimale Abdi
Mar 21 at 22:51













stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

– bk7
Mar 22 at 5:12





stackoverflow.com/questions/1128723/… refer this @jimaleAbdi

– bk7
Mar 22 at 5:12













Thank you @bk7 not works for me

– Jimale Abdi
Mar 22 at 10:55





Thank you @bk7 not works for me

– Jimale Abdi
Mar 22 at 10:55












1 Answer
1






active

oldest

votes


















0














If you want to compare array values to string you can use for loop to check your array values one by one:



 String[] products= "Acer", "HP", "Lenova";
for(String s : products)
if(s.equals("HP"))
startActivity(new Intent(this, hpcomputer.class));




Please note that you are using products.toString() on the entire array so it will look like this:



["Acer", "HP", "Lenova"]


Now, every time that you will use entireString.equal("just part of the string") method the result will return false because the entire string got more chars and it will never be equal to a part of it.



Edit - after seeing your last comment it would be a lot more simple to just check if your item that got clicked was "HP":



public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
String[] products= "Acer", "HP", "Lenova";
if(position == 1)
//"HP" got clicked
else if(position == 2)
//"Lenova" got clicked
else
//"Acer" got clicked







share|improve this answer

























  • Thank you i don't need to use position

    – Jimale Abdi
    Mar 21 at 23:08











  • So what do you need to use?

    – Tamir Abutbul
    Mar 21 at 23:08











  • i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

    – Jimale Abdi
    Mar 21 at 23:12











  • What do you mean by Acer and Lenova? Because my answer is comparing method

    – Tamir Abutbul
    Mar 21 at 23:13











  • Acer and Lenova are other activities

    – Jimale Abdi
    Mar 21 at 23:16











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290275%2fandroid-array-check-values-using-if-statement-inside-listview-onitemclick%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









0














If you want to compare array values to string you can use for loop to check your array values one by one:



 String[] products= "Acer", "HP", "Lenova";
for(String s : products)
if(s.equals("HP"))
startActivity(new Intent(this, hpcomputer.class));




Please note that you are using products.toString() on the entire array so it will look like this:



["Acer", "HP", "Lenova"]


Now, every time that you will use entireString.equal("just part of the string") method the result will return false because the entire string got more chars and it will never be equal to a part of it.



Edit - after seeing your last comment it would be a lot more simple to just check if your item that got clicked was "HP":



public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
String[] products= "Acer", "HP", "Lenova";
if(position == 1)
//"HP" got clicked
else if(position == 2)
//"Lenova" got clicked
else
//"Acer" got clicked







share|improve this answer

























  • Thank you i don't need to use position

    – Jimale Abdi
    Mar 21 at 23:08











  • So what do you need to use?

    – Tamir Abutbul
    Mar 21 at 23:08











  • i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

    – Jimale Abdi
    Mar 21 at 23:12











  • What do you mean by Acer and Lenova? Because my answer is comparing method

    – Tamir Abutbul
    Mar 21 at 23:13











  • Acer and Lenova are other activities

    – Jimale Abdi
    Mar 21 at 23:16















0














If you want to compare array values to string you can use for loop to check your array values one by one:



 String[] products= "Acer", "HP", "Lenova";
for(String s : products)
if(s.equals("HP"))
startActivity(new Intent(this, hpcomputer.class));




Please note that you are using products.toString() on the entire array so it will look like this:



["Acer", "HP", "Lenova"]


Now, every time that you will use entireString.equal("just part of the string") method the result will return false because the entire string got more chars and it will never be equal to a part of it.



Edit - after seeing your last comment it would be a lot more simple to just check if your item that got clicked was "HP":



public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
String[] products= "Acer", "HP", "Lenova";
if(position == 1)
//"HP" got clicked
else if(position == 2)
//"Lenova" got clicked
else
//"Acer" got clicked







share|improve this answer

























  • Thank you i don't need to use position

    – Jimale Abdi
    Mar 21 at 23:08











  • So what do you need to use?

    – Tamir Abutbul
    Mar 21 at 23:08











  • i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

    – Jimale Abdi
    Mar 21 at 23:12











  • What do you mean by Acer and Lenova? Because my answer is comparing method

    – Tamir Abutbul
    Mar 21 at 23:13











  • Acer and Lenova are other activities

    – Jimale Abdi
    Mar 21 at 23:16













0












0








0







If you want to compare array values to string you can use for loop to check your array values one by one:



 String[] products= "Acer", "HP", "Lenova";
for(String s : products)
if(s.equals("HP"))
startActivity(new Intent(this, hpcomputer.class));




Please note that you are using products.toString() on the entire array so it will look like this:



["Acer", "HP", "Lenova"]


Now, every time that you will use entireString.equal("just part of the string") method the result will return false because the entire string got more chars and it will never be equal to a part of it.



Edit - after seeing your last comment it would be a lot more simple to just check if your item that got clicked was "HP":



public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
String[] products= "Acer", "HP", "Lenova";
if(position == 1)
//"HP" got clicked
else if(position == 2)
//"Lenova" got clicked
else
//"Acer" got clicked







share|improve this answer















If you want to compare array values to string you can use for loop to check your array values one by one:



 String[] products= "Acer", "HP", "Lenova";
for(String s : products)
if(s.equals("HP"))
startActivity(new Intent(this, hpcomputer.class));




Please note that you are using products.toString() on the entire array so it will look like this:



["Acer", "HP", "Lenova"]


Now, every time that you will use entireString.equal("just part of the string") method the result will return false because the entire string got more chars and it will never be equal to a part of it.



Edit - after seeing your last comment it would be a lot more simple to just check if your item that got clicked was "HP":



public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) 
String[] products= "Acer", "HP", "Lenova";
if(position == 1)
//"HP" got clicked
else if(position == 2)
//"Lenova" got clicked
else
//"Acer" got clicked








share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 21 at 23:21

























answered Mar 21 at 22:52









Tamir AbutbulTamir Abutbul

2,2642823




2,2642823












  • Thank you i don't need to use position

    – Jimale Abdi
    Mar 21 at 23:08











  • So what do you need to use?

    – Tamir Abutbul
    Mar 21 at 23:08











  • i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

    – Jimale Abdi
    Mar 21 at 23:12











  • What do you mean by Acer and Lenova? Because my answer is comparing method

    – Tamir Abutbul
    Mar 21 at 23:13











  • Acer and Lenova are other activities

    – Jimale Abdi
    Mar 21 at 23:16

















  • Thank you i don't need to use position

    – Jimale Abdi
    Mar 21 at 23:08











  • So what do you need to use?

    – Tamir Abutbul
    Mar 21 at 23:08











  • i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

    – Jimale Abdi
    Mar 21 at 23:12











  • What do you mean by Acer and Lenova? Because my answer is comparing method

    – Tamir Abutbul
    Mar 21 at 23:13











  • Acer and Lenova are other activities

    – Jimale Abdi
    Mar 21 at 23:16
















Thank you i don't need to use position

– Jimale Abdi
Mar 21 at 23:08





Thank you i don't need to use position

– Jimale Abdi
Mar 21 at 23:08













So what do you need to use?

– Tamir Abutbul
Mar 21 at 23:08





So what do you need to use?

– Tamir Abutbul
Mar 21 at 23:08













i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

– Jimale Abdi
Mar 21 at 23:12





i need to use comparing method, your above is working but when i click HP it opens the HP activity after that when i press back also it opens Acer and Lenova

– Jimale Abdi
Mar 21 at 23:12













What do you mean by Acer and Lenova? Because my answer is comparing method

– Tamir Abutbul
Mar 21 at 23:13





What do you mean by Acer and Lenova? Because my answer is comparing method

– Tamir Abutbul
Mar 21 at 23:13













Acer and Lenova are other activities

– Jimale Abdi
Mar 21 at 23:16





Acer and Lenova are other activities

– Jimale Abdi
Mar 21 at 23:16



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290275%2fandroid-array-check-values-using-if-statement-inside-listview-onitemclick%23new-answer', 'question_page');

);

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







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해