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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:22:44+00:00 2026-06-11T22:22:44+00:00

i am working on implementing list view, i have user BaseAdapter class.i am trying

  • 0

i am working on implementing list view, i have user BaseAdapter class.i am trying to setText in holder’s text view field from an array list but without any success.Problem is in getView method’s HashMap<String, ArrayList<String>> map = list.get(position);
holder.txtFirst.setText(map.get(FIRST_COLUMN).toString());
part.
EDIT:
my main activity class(postExecute method) where i am setting up key and values for list adapter class. code is as :

protected void onPostExecute(ArrayList<ArrayList<String>> result) {

        ArrayList<String> conceptID = new ArrayList<String>(result.get(0));
        ArrayList<String> conceptDesc = new ArrayList<String>(result.get(1));

        listForSearchConcepts = new ArrayList<HashMap<String,ArrayList<String>>>();
        HashMap<String, ArrayList<String>> temp = new HashMap<String,ArrayList<String>>();
        temp.put(FIRST_COLUMN,conceptID);
        listForSearchConcepts.add(temp);
        temp.put(SECOND_COLUMN,conceptDesc);
        listForSearchConcepts.add(temp);
        listviewAdapter adapter = new listviewAdapter(MainActivity.this, listForSearchConcepts);
        listView.setAdapter(adapter);
    }`   

However below is my code of adapter class :

public class listviewAdapter extends BaseAdapter
{
public ArrayList< HashMap < String,ArrayList < String > > > list;
Activity activity;

public listviewAdapter(Activity activity, ArrayList<HashMap<String,ArrayList<String>>> listForSearchConcepts) {
    super();
    this.activity = activity;
    this.list = listForSearchConcepts;
}

public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

private class ViewHolder {
       TextView txtFirst;
       TextView txtSecond;
       TextView txtThird;
       TextView txtFourth;
  }


public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    // TODO Auto-generated method stub
            ViewHolder holder;
            LayoutInflater inflater =  activity.getLayoutInflater();

            if (convertView == null)
            {
                convertView = inflater.inflate(R.layout.listview_row, null);
                holder = new ViewHolder();
                holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText);
                holder.txtSecond = (TextView) convertView.findViewById(R.id.SecondText);
                convertView.setTag(holder);
            }
            else
            {
                holder = (ViewHolder) convertView.getTag();
            }

            HashMap<String, ArrayList<String>> map = list.get(position);
            holder.txtFirst.setText(map.get(FIRST_COLUMN).toString());
            //holder.txtSecond.setText(map.get(SECOND_COLUMN).get(1));
            //holder.txtThird.setText(map.get(THIRD_COLUMN));
            //holder.txtFourth.setText(map.get(FOURTH_COLUMN));

        return convertView;
}

}

i am also attaching screenshot of what actually i am getting on running the application:
out put list view

any suggestion?
thanks

  • 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-11T22:22:45+00:00Added an answer on June 11, 2026 at 10:22 pm

    I strongly encourage you to replace your hasmaps and arraylists with classes. Java has poor capability to work with structures using map-lists. It just looks ugly in java. You can create class Concept that contain 2 fields: id and description. And in postExecute method you convert your lists to list of concepts. Something like this:

    Concept class:

    public class Concept {
    
        public String id;
        public String description;
    }
    

    onPostExecute method:

    protected void onPostExecute(List<List<String>> result) {
    
        List<String> conceptID = result.get(0);
        List<String> conceptDesc = result.get(1);
    
        List<Concept> listForSearchConcepts = new ArrayList<Concept>();
        for (int i = 0; i < conceptID.size(); i++) {
            Concept concept = new Concept();
            concept.id = conceptID.get(i);
            concept.description = conceptDesc.get(i);
            listForSearchConcepts.add(concept);
        }
        ListViewAdapter adapter = new ListViewAdapter(MainActivity.this, listForSearchConcepts);
        listView.setAdapter(adapter);
    }
    

    ListViewAdapter class:

    class ListviewAdapter extends BaseAdapter
    {
        public List<Concept> list;
        Activity activity;
    
        public ListviewAdapter(Activity activity, List<Concept> listForSearchConcepts) {
            super();
            this.activity = activity;
            this.list = listForSearchConcepts;
        }
    
        public int getCount() {
            return list.size();
        }
    
        public Object getItem(int position) {
            return list.get(position);
        }
    
        public long getItemId(int position) {
            return 0;
        }
    
        private class ViewHolder {
            TextView txtFirst;
            TextView txtSecond;
            TextView txtThird;
            TextView txtFourth;
        }
    
    
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
    
            // TODO Auto-generated method stub
            ViewHolder holder;
            LayoutInflater inflater =  activity.getLayoutInflater();
    
            if (convertView == null)
            {
                convertView = inflater.inflate(R.layout.listview_row, null);
                holder = new ViewHolder();
                holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText);
                holder.txtSecond = (TextView) convertView.findViewById(R.id.SecondText);
                convertView.setTag(holder);
            }
            else
            {
                holder = (ViewHolder) convertView.getTag();
            }
    
            Concept concept = list.get(position);
            holder.txtFirst.setText(concept.id);
            holder.txtSecond.setText(concept.description);
    
            return convertView;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on implementing a class for managing user permissions on my website. For
This is homework I'm working on implementing a linked list class for my C++
I am currently implementing a ListView populated with CheckedTextViews and have everything working just
I'm working on implementing a cache for a lot of bitmap tiles I have.
I'm working on implementing a way to allow HTML in a field that I
The application I've been working on takes user input from a form, and builds
I've been implementing a grid view of some content - and I have it
I'm currently working on implementing a list-type structure at work, and I need it
For a project I'm working on, I'm implementing a linked-list data-structure, which is based
For a project I'm working on, I'm implementing a linked-list data-structure, which is based

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.