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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

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

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?