Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:33:20+00:00 2026-06-15T09:33:20+00:00

i want to compare arraylist with a textview, when the value of arraylist and

  • 0

i want to compare arraylist with a textview, when the value of arraylist and textview is match/same, i want to show the index of the arraylist..

this is my code

TextView namamenu2=(TextView)findViewById(R.id.nama_menu2);         
String nama_menu_upd = namamenu2.getText().toString();

for(MenuInputClass mic2 : results) {    
    String comp=mic2.getNama_menu();
    if(nama_menu_upd.equals(comp))
    {                               
        int compIndex=results.indexOf(comp);
        Toast.makeText(Appetizer_Activity.this,compIndex, Toast.LENGTH_LONG).show();                                
    }       
} 

MenuInputClass

public class MenuInputClass {

    private String nama_menu;
    private String jumlah_menu;

    public void setNama_menu(String nama_menu) {
        this.nama_menu=nama_menu;
    }

    public String getNama_menu() {
        return (nama_menu);
    }
}

when i show compIndex on Toast, its always show -1.But when i try to show the size of result , its show correct size.how can i fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:33:22+00:00Added an answer on June 15, 2026 at 9:33 am

    Try normal For loop instead Foreach, Foreach will not let you know that index unless you take a int counter.

    With Normal For:

    for(int i=0; i< results.size(); i++) {    
            MenuInputClass mic2= results.get(i);
            String comp=mic2.getNama_menu();
            if(nama_menu_upd.equals(comp))
            {                               
                Toast.makeText(Appetizer_Activity.this, i, Toast.LENGTH_LONG).show();                                
            }       
        } 
    

    With Foreach:

    int counter=0;
    for(MenuInputClass mic2 : results) {    
        String comp=mic2.getNama_menu();
        if(nama_menu_upd.equals(comp))
        {                               
            Toast.makeText(Appetizer_Activity.this, counter, Toast.LENGTH_LONG).show();                                
        }  
         counter++;     
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a pice of my code : ArrayList<String> Alist= new ArrayList<String>(); ArrayList<String> Blist=
I want to do exactly like this in java Compare two string ArrayLists the
I want to compare two Lists in test. I have this code @Test public
I want to compare the first few bytes in byte[] with a string. How
I want to compare two different types of array list i.e. ArrayList<A> list1 =
I want to compare string which is date. I am trying following linq query,
I want to show data in this format, 12-22-2011 11:00:00 [12-22-2011 11:13:39] Warning: Contact
I have two ArrayList . Each is of size 100000. I want to compare
I have two arraylist fileWordList and stopWordList. I want to compare fileWordList to stopWordList
I want to sort an Hashmap by the object's value. In this case, by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.