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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:34:05+00:00 2026-05-23T12:34:05+00:00

Actually I have created a custom ListView . I want to add items to

  • 0

Actually I have created a custom ListView. I want to add items to this custom ListView dynamically. But in my case, the first item is inserted without any problem but when I try to insert the second item it gives an error. If anyone knows how to solve this, please suggest it to me.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/historyFrmLstView2"
android:layout_alignParentLeft="true"
android:layout_below="@+id/historyFrmLstView1"
android:layout_marginTop="20dip"
android:layout_marginBottom="10dip">
</ListView> 

 </RelativeLayout>

ListView.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dip"
android:background="#00000000">
<TextView
    android:textSize="18dp"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:background="@drawable/history_scroll_title_label_bg"
    android:layout_width="wrap_content"
    android:id="@+id/txtHistoryDisplay"
    android:layout_below="@+id/txtViewHeading"
    android:layout_marginTop="0dip"
    android:layout_marginLeft="2dip">
</TextView>  

 </RelativeLayout>

main.java

 public void displayHistory()
 {
    String strDisplay[] = {" "};
    historyFrmLstView2 = (ListView) findViewById(R.id.historyFrmLstView2);
    int iHistCount = CycleManager.getSingletonObject().getHistoryCount();
    int i;
    SimpleDateFormat sdFormatter = new SimpleDateFormat("dd-MMMM-yyyy");

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

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

            strDisplay[i]=sdFormatter.format(dtHist.getTime());

            aHistFrmAdpter2 = new HistoryFrmCustomAdapter2(this,strDisplay);
            historyFrmLstView2.setAdapter(aHistFrmAdpter2);  
    }
 }

custom Adapter.java

public class HistoryFrmCustomAdapter2 extends BaseAdapter
{

public String heading1[];
public Activity context;
public LayoutInflater inflater;

public HistoryFrmCustomAdapter2(Activity context,String[] heading1) 
{
    super();
    this.context = context;
    this.heading1=heading1;
    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() 
{
    return heading1.length; 
}

public Object getItem(int position) 
{   
    return null;
}
public long getItemId(int position) 
{
    return 0;
}
public static class ViewHolder
{
    TextView txtHistoryDisplay;
}
public View getView(int position, View convertView, ViewGroup parent) 
{
    ViewHolder holder;

    if(convertView==null)
    {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.histryfrm_listview2, null);

        holder.txtHistoryDisplay =(TextView) convertView.findViewById(R.id.txtHistoryDisplay);

        convertView.setTag(holder);
    }
    else
        holder=(ViewHolder)convertView.getTag();
    holder.txtHistoryDisplay.setText(heading1[position]);
    return convertView;
} 
}
  • 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-23T12:34:05+00:00Added an answer on May 23, 2026 at 12:34 pm

    Hi i think that may be used below code..

    public void displayHistory()
     {
        String strDisplay[] = {" "};
        historyFrmLstView2 = (ListView) findViewById(R.id.historyFrmLstView2);
        int iHistCount = CycleManager.getSingletonObject().getHistoryCount();
        int i;
        SimpleDateFormat sdFormatter = new SimpleDateFormat("dd-MMMM-yyyy");
    
        for (i=0; i<iHistCount; i++)
        {
                strDisplay[i] = "";
    
                Date dtHist = CycleManager.getSingletonObject().getHistoryDate(iHistCount);
    
                strDisplay[i]=sdFormatter.format(dtHist.getTime());
    
    
        }
    
         aHistFrmAdpter2 = new HistoryFrmCustomAdapter2(this,strDisplay);
         historyFrmLstView2.setAdapter(aHistFrmAdpter2);  
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom tag that looks like this: def textField = {
I have created a Word add-in which would load data in custom ribbon from
So I have: created a couple of custom controllers (add file UIViewController subclass) in
I have an onclick handler for an <a> element (actually, it's a jQuery-created handler,
I actually have an answer to my question but it is not parallelized so
I actually have two questions regarding the same problem but I think it is
I would actually love to have an AlternatingItemTemplate on a GridView, but all it
I always have found the open source space interesting but have never actually participated
I have created a custom control (based on a panel) in wxPython that provides
As part of a CMS, I have created a custom VirtualPathProvider which is designed

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.