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

  • Home
  • SEARCH
  • 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 9058073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:37:44+00:00 2026-06-16T14:37:44+00:00

I am adding textviews dynamically to a linear layout and want to get the

  • 0

I am adding textviews dynamically to a linear layout and want to get the name of the textview clicked in OnClickListener of linear layout.This is the code:

m_lvSideIndex = (LinearLayout)ShowTheContacts1.this.findViewById(R.id.sideIndex);
TextView l_tempText = null;

for(int l_a = 0;l_a < m_arrayOfAlphabets.length;l_a++)
{
    l_tempText = new TextView(ShowTheContacts1.this);
    l_tempText.setGravity(Gravity.CENTER);
    l_tempText.setTextSize(15);
    l_tempText.setTextColor(getResources().getColor(R.color.black));
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
    l_tempText.setLayoutParams(params);;
    l_tempText.setText(m_arrayOfAlphabets[l_a]);
    m_lvSideIndex.addView(l_tempText);
    m_lvSideIndex.setTag(l_a);
}

m_lvSideIndex.setOnClickListener(new OnClickListener() 
{               
    @Override
    public void onClick(View v) 
    {
        String l_itemSelected = (String)v.toString();  //Want to get the name of textview selected here
});

Please help me.Thanks in advance.

  • 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-16T14:37:45+00:00Added an answer on June 16, 2026 at 2:37 pm

    You can do with it the help of getTag()

    first setTag() the value i.e TextName

    m_lvSideIndex.setTag(m_arrayOfAlphabets[l_a]);
    m_lvSideIndex.setTag(l_a, R.id.sideIndex);
    

    and get the value via getTag()

    m_lvSideIndex.setOnClickListener(new OnClickListener() 
    {               
        @Override
        public void onClick(View v) 
        {
            String l_itemSelected = (String)v.getTag(); 
            Integer l_position = (Integer)v.getTag(R.id.sideIndex);   
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm adding TextViews dynamically with code. Now I'm using a LinearLayout with horizontal orientation
I have a LinearLayout, I am dynamically adding TextView, ImageView to that LinearLayout ,
I'm adding in a TextView programatically to a linear layout. I can see the
I am adding TextViews to my layout and I want to keep them when
I am adding Linearlayout dynamically and adding 3 TextView getting the content from webservices
I am creating a textview and adding to the layout dynamically. I am using
I am creating a ListView dynamically and want to add two TextViews in a
I am adding a spinner dynamically in a layout, as; public class FRQuestionsDetail extends
I would like to add programmatically to LinearLayout some TextViews . And I want
I want to create a XML layout dynamically but I had a question on

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.