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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:02:11+00:00 2026-05-23T16:02:11+00:00

Actually, in my app I want to insert TextView in the ListView dynamically but

  • 0

Actually, in my app I want to insert TextView in the ListView dynamically but how can I do it? I don’t have any idea. I am sending my code where I use textView which I want to insert in the ListView dynamically. Can anyone please suggest it to me? If possible with examples.

My current code:

public void displayHistory()
{

        int iHistCount = CycleManager.getSingletonObject().getHistoryCount();
        String strDisplay;
        int i;
        boolean bStarred = false;

        SimpleDateFormat sdFormatter = new SimpleDateFormat("dd-MMMM-yyyy");

        for (i=0; i<iHistCount; i++)
        {
                strDisplay = "";

                Date dtHist = CycleManager.getSingletonObject().getHistoryDate(i);

                strDisplay=sdFormatter.format(dtHist.getTime());

                LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayoutHist1);

                LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1);

                LinearLayout rowLayout=new LinearLayout(this) ;

                layoutVertical.addView(rowLayout,param);

                TextView tTextHistory1=new TextView(this);
                tTextHistory1.setTextColor(Color.parseColor("#000000"));
                tTextHistory1.setPadding(15, 0, 0, 0);
                tTextHistory1.setText(strDisplay);

                rowLayout.setBackgroundResource(R.drawable.history_scroll_label_bg);
                rowLayout.addView(tTextHistory1,param);

                strDisplay=" ";

                if (i == 0)
                       if (CycleManager.getSingletonObject().isCycleStopped())
                               strDisplay = "Stopped";
                       else
                               strDisplay = "In progress";
                else
                {
                         Date dtNextHist = CycleManager.getSingletonObject().getHistoryDate(i-1);
                         long lDiff =dtNextHist.getTime()-dtHist.getTime();
                         lDiff=lDiff/(1000 * 60 * 60 * 24);

                         strDisplay=Long.toString(lDiff);

                         if (lDiff<DeclareVariable.CYCLE_MIN_LENGTH || lDiff>DeclareVariable.CYCLE_MAX_LENGTH)
                         {
                                 strDisplay=strDisplay+"*";
                                 bStarred = true;
                         }
                 }

                TextView tTextHistory2=new TextView(this);
                tTextHistory2.setTextColor(Color.parseColor("#000000"));
                tTextHistory2.setPadding(15, 0, 0, 0);
                tTextHistory2.setText(strDisplay);
                rowLayout.addView(tTextHistory2,param);  

        }
        strDisplay=" ";
        if (bStarred)
                strDisplay="* Shorter or longer than accepted";
        else
                strDisplay=" ";

        TextView tTextHistory3=(TextView) findViewById(R.id.txtViewHeading);
        tTextHistory3.setTextColor(Color.parseColor("#000000"));
        tTextHistory3.setPadding(15, 0, 0, 0);
        tTextHistory3.setText(strDisplay);
}
  • 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-05-23T16:02:12+00:00Added an answer on May 23, 2026 at 4:02 pm

    I am not 100% sure if I understand what you are asking, but if you want to add things from a datasource you need to add a ListAdapter, which allows the list to populate from a datasource. The best way to do this is with an inflater. Below is some code I am using for my Android app that fetches data from a URL and populates it. Let me know if you need more clarification!

    Here’s a link to a tutorial as well: http://www.vogella.de/articles/AndroidListView/article.html

    public class CheckinList extends ListActivity {
    
        private LayoutInflater mInflater;
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
                final ListView list = getListView();
                mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                list.setAdapter(new ArrayAdapter<CheckinItem>(this, R.layout.checkin_item, main.Crunch) {
                      @Override
                      public View getView(int position, View convertView, ViewGroup parent) {
                          View row;
                          if (null == convertView) {
                                row = mInflater.inflate(R.layout.checkin_item, null);
                            } else {
                                row = convertView;
                            }
                          TextView name = (TextView) row.findViewById(R.id.name);
                          name.setText(getItem(position).getVenueName());
                          TextView time = (TextView) row.findViewById(R.id.time);
                          time.setText(getItem(position).getTime().toString());
                          TextView address = (TextView) row.findViewById(R.id.address);
                          address.setText(getItem(position).getAddress());
                          TextView crossStreet = (TextView) row.findViewById(R.id.crossStreet);
                          if(getItem(position).getCrossStreet() != ""){
                              address.append(", ");
                              crossStreet.setText(getItem(position).getCrossStreet());
                          }
                          return row;
                      }
                  });
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually i have created an app from which i can stored notes to my
I actually have two questions regarding exception/error handling in the iPhone app that I
I have a WPF application that is a fullscreen kiosk app. It's actually a
I have a Google App engine application that I want to work differently depending
I realise that you can't use in app purchases for real things. But does
I have a flex app that I want to hide in a div until
Actually i want to change the text color of the listview that i had
I have a web app which I can create some notes, each time I
in my app I want to have a searchbar like in the weather app
I'm building a web app,which actually does image compression for the user's image,I want

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.