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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:07:23+00:00 2026-05-23T22:07:23+00:00

My application has 24 buttons to count different vehicle types and directions (the app

  • 0

My application has 24 buttons to count different vehicle types and directions (the app will be used to count traffic). Currently, I’m saving a line to a .csv file each time a button is pressed. The csv file contains a timestamp, direction, etc.

I have to measure how many times every button was pressed in 15-minute intervals.

How should I store the counters for the buttons?
I just need to output how often every button (every button has a different tag for identification) was pressed in 15 minutes.

I was thinking about using a HashMap, which could just take the button’s tag as key and the number of occurrences as value, like this:

HashMap<String, Integer> hm = new HashMap<String, Integer>();

Integer value = (Integer) hm.get(buttonTag);
    if (value == null) {
        hm.put(buttonTag, 1);
    } else {
        int nr_occ = value.intValue() + 1;
        hm.put(buttonTag, nr_occ);
    }

However, I don’t need the total sums of button presses, but in 15 minute chunks. And as I’m already writing timestamps to the raw csv-file, I’m wondering how I should store these values.

Edit: I’m currently testing the HashMap, and it’s working really well for counting, but I see two issues: first of all, grouping it into 15-minute intervals and secondly, the hashmap isn’t sorted in any way. I’d need to output the values sorted by vehicle types and directions.

  • 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-23T22:07:25+00:00Added an answer on May 23, 2026 at 10:07 pm

    If your data is simple (i.e. you only need a key/value pair) then consider using SharedPreferences to store the button id and the time it was pressed.

    This is a good way because it is extremely fast. You already put the info into a .csv file but to extract the data and traverse through it so that you can compare timestamps is too much overhead IMO.

    When a button is pressed store your data in the .csv file then also store the key/value (id/timestamp) then you can iterate through that and do your compare and output whatever you need to output.

    The other way (and probably even better) is to simply create and write to your .csv file, then dump it and use something else more robust to process that data as you will probably be doing this anyway.

    EDIT: I see a lot of answers which are saying to use SQLite, statics, etc…

    These are all inferior methods for what you are asking. Here is why…
    SQLite is WAY too much for just a simple button id and timestamp. However if you think you might need to store more data in the future this may in fact be an option.

    A static variable might be destroyed if the system happens to destroy the Activity.

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

Sidebar

Related Questions

I was given a task. First dialog based application has 4 buttons (up, down,
I have an application that has a list of buttons and has customized tooltips.
I am building a simple application that has a few buttons that when clicked
In my application I have several activities, the main screen has 4 buttons that
I embedded .NET's WebBrowser into a form that has some other buttons. The application
I'm working on an application guess the number. If the user has used all
I have a very basic application that has buttons in a toolstrip. When a
My application has a toolbar with ImageButtons that I use as application buttons. I
My application has a frame that is loaded/navigated when certain top-level buttons are clicked.
I'm trying to make an application that has specifically styled buttons. To do this

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.