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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:33+00:00 2026-06-12T01:38:33+00:00

I have to put a list of names queried from database into a list

  • 0

I have to put a list of names queried from database into a list (not listview). I am able to do that by inflating a linearlayout with a custom view. I have a created a new class in which there is a method which inflates the layout with the custom view.
In that method I have implemented a onclicklistener, but it is not working.
Code:

public static void showPeopleInvitedList(Context context, View view, final LinearLayout layout) {
    dbAdapter = new DatabaseHandler(context);
    String[] ENTRIES = dbAdapter.getItems("user_friend_name");
    for (int i = 0; i < 5; i++ ) {
        LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.people, layout, false);

        view.setId(layout.getChildCount() + 1);
        params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        view.setLayoutParams(params);
        view.setOnClickListener(myClickListener);
        layout.addView(view, 0, params);    


    }

    myClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d("click", "clicked");
            layout.removeView(v);
        }
    };
}

But onclicklistener is not working. I am calling this method in the main activity. This method is inside a class which extends LinearLayout
Any suggestions?

  • 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-12T01:38:34+00:00Added an answer on June 12, 2026 at 1:38 am

    You have not yet instantiated myClickListener, so you are setting the view’s onClickListener to null. Move its initialization to before your for loop.

    public static void showPeopleInvitedList(Context context, View view, final LinearLayout layout) {
        dbAdapter = new DatabaseHandler(context);
        String[] ENTRIES = dbAdapter.getItems("user_friend_name");
    
        myClickListener = new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                Log.d("click", "clicked");
                layout.removeView(v);
            }
        };
        for (int i = 0; i < 5; i++ ) {
            LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflator.inflate(R.layout.people, layout, false);
    
            view.setId(layout.getChildCount() + 1);
            params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    
            view.setLayoutParams(params);
            view.setOnClickListener(myClickListener);
            layout.addView(view, 0, params);    
    
    
        }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that takes a list of names from a file and
I have a big list and put it into a treemap. Then I want
I have a list that I want to put in a dictionary, for simplicity
I have a list of numbers and need to put them all into a
I have a list of names, that contain this: <td><%= product.date %></td> and it
I have a simple form that I use to list the names of all
I have a list of names that I'm displaying in one cell of a
In Excel I have a list of names that in the cell appear stacked,
I have to implement a one linked list but it should put object in
I have a drop down list and I want the selected value to put

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.