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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:11:33+00:00 2026-06-13T06:11:33+00:00

So The problem I’m having is that I have a hashtable with the key

  • 0

So The problem I’m having is that I have a hashtable with the key values being

Key: Integer
Value: ArrayList

In my custom listView adapter I have it set to only display the values at a certain position in the hashtable..but at the moment it’s displaying the entire hashtable. I’m not quite sure what I’m doing wrong.. Here’s the adapter

Note: Statics.mainPageListPosition is a static int that gets set when the user clicks on a certain position on the main screen. I want the adapter then to display that position, and only that position’s data.

package assignments;

import java.util.ArrayList;
import java.util.Hashtable;

import com.example.mt_study.R;
import com.example.statics.Statics;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class AssignmentListViewAdapter extends ArrayAdapter<Assignment> {

    private LayoutInflater inflater;
    private Hashtable<Integer, ArrayList<Assignment>> assignmentList;

    // class used to hold views when the user scrolls on the listView
    // it stores them and then we can re-use their id's as the user scrolls
    // down or up the screen so we don't have to keep calling findViewById
    private class assignmentViewHolder {
        TextView Title;
        TextView Date;

        public assignmentViewHolder(TextView assignmentTitle, TextView Date) {
            this.Title = assignmentTitle;
            this.Date = Date;
        }

        public TextView getTitle() {
            return Title;
        }

        public TextView getDate() {
            return Date;
        }
    }

    public AssignmentListViewAdapter(Context context,
            Hashtable<Integer, ArrayList<Assignment>> data) {
        super(context, R.id.assignment_row_title, R.id.assignment_row_date);
        inflater = LayoutInflater.from(context);
        assignmentList = data;

    }

    // set of functions useful for the getView function
    public int getCount() {
        return Statics.allAssignments.get(Statics.mainPageListPosition).size();
    }

    public Assignment getItem(int position) {
        return assignmentList.get(Statics.mainPageListPosition).get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public int getViewTypeCount() {
        return 1;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // Assignment assignment = this.getItem(position);

        TextView assignmentTitle;
        TextView assignmentDate;

        // if theres no view yet created on the screen, create one
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.assignment_row, null);

            // give the views their respective ID's
            assignmentTitle = (TextView) convertView
                    .findViewById(R.id.assignment_row_title);
            assignmentDate = (TextView) convertView
                    .findViewById(R.id.assignment_row_date);

            // set the tag so we can just use the viewHolder instead of calling
            // findViewById over. It saves memory
            convertView.setTag(new assignmentViewHolder(assignmentTitle,
                    assignmentDate));
        }
        // this gets called when the user scrolls down or up the screen and the
        // adapter
        // wants to maximize efficiency by just calling the viewHolder instead
        // of findViewById
        else {
            assignmentViewHolder viewHolder = (assignmentViewHolder) convertView
                    .getTag();
            assignmentTitle = viewHolder.getTitle();
            assignmentDate = viewHolder.getDate();

        }
        // down here is where you set the values for all your views/objects
        // such as Buttons or textViews.
        assignmentTitle.setText(Statics.allAssignments
                .get(Statics.mainPageListPosition).get(position).getTitle());
        assignmentDate.setText(Statics.allAssignments
                .get(Statics.mainPageListPosition).get(position).getDate_due());

        return convertView;
    }
}

Edit: recent discovery, that my hashtable puts every value I send it in every position available lol. What I do is when the user clicks on a position on the main page it saves that position and uses it to store the data they save at that position in the hashtable. Temp is an arrayList with the user’s saved data stored in this format :

{number, String, number, string}
Where the number is the position in the hashtable I want to store the string.

Here is where I’m saving the data to the hashtable. Everything looks right to me, maybe i’ve been staring at it too long @.@

for (int i = 0; i < temp.size(); i++) {
                if (isInteger(temp.get(i))) {
                    currentAssignment.setTitle(temp.get(i + 1));
                    //currentAssignment.setDate_due(temp.get(i + 2));
                    currentAssignmentList.add(index, currentAssignment);
                    index++;

                    Statics.allAssignments.put(Integer.parseInt(temp.get(i)), currentAssignmentList);
                    //Statics.allAssignments.get(Integer.parseInt(temp.get(i))).add(currentAssignment);
                    currentAssignment = new Assignment();
                    //Toast.makeText(context, "Called" + Integer.toString(i), Toast.LENGTH_SHORT).show();
                }
            }
  • 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-13T06:11:34+00:00Added an answer on June 13, 2026 at 6:11 am

    Where are you setting the list of items on the ArrayAdapter? I think you should use your data constructor parameter, either with addAll(data) or in your call to super(). Note that you currently ignore this data in getView() and use your statics instead. In getView(), once you have items correctly set in the superclass ArrayAdapter, you should use Assignment a = getItem(position) and set your fields from this object instead of your statics.

    E.g. in the constructor…

    super(context, R.id.assignment_row_title, R.id.assignment_row_date, data);
    

    Then in getView()…

    Assignment a = getItem(position);
    assignmentTitle.setText(a.getTitle());
    assignmentDate.setText(a.getDate_due());
    

    This of course assumes that the list you pass in as data is correct. Hopefully once you have your code looking at only one list of items you can more easily verify that this list is correct.

    Edit:

    In your second chunk of code, where do you make a new currentAssignmentList for each hash table key? If you assign the same object to all entries your hash table, then they will all contain the same list.

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

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
Problem background: I have a Qt/QML Symbian application targeting Qt 4.7.4, that requires a
Problem description I have 6 databases from 6 different machines, and having one cloud
Problem: I have a WCF service that invokes methods via reflection and sends the
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: I have code that looks for a file and open it. By default
Problem: When adding list item the Value field is being set to the Text
Problem: I have two array where one produce a category and the second produce
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
Problem occured when i tried to display xml data that has been taken by

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.