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 8513197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:29:25+00:00 2026-06-11T04:29:25+00:00

im a noob to android and i am populating a listview with an arrayilst

  • 0

im a noob to android and i am populating a listview with an arrayilst and custom adapter. I want setup my listview onClickListener to execute commands based to the the items populating the listview. the listview is dynamically populated with items from the arraylist. I have tried the position and id parameters with no luck. Any help is greatly appreciated.

How I instantiate listview, arraylist, and adapter

    portfoliolist = (ListView) findViewById(R.id.listViewPortfolios);
    users = new ArrayList<PortfolioRecord>();
    portfoliolist.setAdapter(new UserItemAdapter(this, R.layout.simplerow, users));
    portfoliolist.setOnItemClickListener(this);     

My Custom Adapter.

public class UserItemAdapter extends ArrayAdapter<PortfolioRecord> {
    private ArrayList<PortfolioRecord> users;

    public UserItemAdapter(Context context, int textViewResourceId, ArrayList<PortfolioRecord> users) {
        super(context, textViewResourceId, users);
        this.users = users;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.simplerow, null);
        }

        PortfolioRecord user = users.get(position);         
        if (user != null) {
            TextView portfolioname = (TextView) v.findViewById(R.id.portfolioname);
            TextView currentvalue = (TextView) v.findViewById(R.id.currentvalue);

            if (portfolioname != null) {
                portfolioname.setText(user.portfolioname);
            }

            if(currentvalue != null) {
                currentvalue.setText("Current Value: " + user.currentvalue );
            }
        }
        return v;
    }
}

public class PortfolioRecord {
    public String portfolioname;
    public String currentvalue;

    public PortfolioRecord(String portfolioname, String currentvalue) {
        this.portfolioname = portfolioname;
        this.currentvalue = currentvalue;       
    }
}

How i add items to arraylist:

            user1 = new PortfolioRecord(pn10, denomination10+portfoliovalue10);        
        users.add(user1);

I have added Usernull, user1 and user2 to my arraylist. How do i identify these items? I’ve tried the folowing code with no luck

public void onItemClick(AdapterView parent, View itemClicked, int position,
        long id) {
     TODO Auto-generated method stub
    switch(parent.getId()){
    case R.id.listViewPortfolios:
        if(portfoliolist.getSelectedItem()==usernull){
            openCustomDialog();
        }else if(portfoliolist.getSelectedItem()==user1){
            whichportfolio=1;               
        }else if(portfoliolist.getSelectedItem()==user2){
            whichportfolio=2;               
        }
     break;}}
  • 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-11T04:29:27+00:00Added an answer on June 11, 2026 at 4:29 am

    No need to implement OnItemSelectedListener. Just use this within the existing OnItemClick method:

    public void onItemClick(AdapterView parent, View itemClicked, int position,
            long id) {
        // TODO Auto-generated method stub
         PortfolioRecord user = users.get(position);
    
            // I'm not certain what this code block does...
            if(user.equals(usernull)){
                 openCustomDialog();
            }else if(user.equals(user1)){
                whichportfolio=1;              
            }else if(user.equals(user2)){
                whichportfolio=2;             
            }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a noob to Android (and Java). I have successfully setup Eclipse and
noob Android/JSON person here. I hope someone might help me? I've looked and looked
android noob... I have two tables, with a one to many relationship between country_tbl
I'm writing my first android app (I'm a noob at android, but decent at
Im an Android noob, coming from objC, I have a very stupid question (project
I'm kinda noob to android so please bear with me. I'm currently developing app
Hii everybody , I am noob at android and need some help... I am
I'm kind of a noob in the android world, and doing a pet project
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initControls(); } I'm a noob android coder.
This is an Android noob question. I am trying to start an activity of

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.