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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:14:09+00:00 2026-05-27T03:14:09+00:00

I have 5 editTexts and 2 buttons for each editText so 10 of them.

  • 0

I have 5 editTexts and 2 buttons for each editText so 10 of them. Each one is supposed to increment/decrement a specific editText. Now my code works entirely but as you’ll soon see, it is not efficient and doesn’t even make sure the numbers are between 0-59 (clock that can be set for n minutes) for the editTexts that are supposed to contain minutes. Anyhow I just want to know the best or most-efficient way to properly do this.

My idea was to have a separate method that takes in parameters such as the specific editText to increment/decrement and another param for whether to add or subtract but I am not sure for the implementation since OnClickListener() has to have the public void onClick(View v) method.

Thanks!

Code:

package com.clock;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class addCourse extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addcourse);

    final Button save_Button = (Button) findViewById(R.id.addSave);
    final Button cancel_Button = (Button) findViewById(R.id.addCancel);
    final Button higherNumber_Button = (Button) findViewById(R.id.higherNumber_Button);
    final Button lowerNumber_Button = (Button) findViewById(R.id.lowerNumber_Button);
    final Button higherClasshh_Button = (Button) findViewById(R.id.higherClasshh_Button);
    final Button lowerClasshh_Button = (Button) findViewById(R.id.lowerClasshh_Button);
    final Button higherClassmm_Button = (Button) findViewById(R.id.higherClassmm_Button);
    final Button lowerClassmm_Button = (Button) findViewById(R.id.lowerClassmm_Button);
    final Button higherClockhh_Button = (Button) findViewById(R.id.higherClockhh_Button);
    final Button lowerClockhh_Button = (Button) findViewById(R.id.lowerClockhh_Button);
    final Button higherClockmm_Button = (Button) findViewById(R.id.higherClockmm_Button);
    final Button lowerClockmm_Button = (Button) findViewById(R.id.lowerClockmm_Button);
    final EditText courseCredits_Edit = (EditText) findViewById(R.id.courseCredits_Edit);
    final EditText hhClass_Edit = (EditText) findViewById(R.id.classHours_Edit);
    final EditText mmClass_Edit = (EditText) findViewById(R.id.classMins_Edit);
    final EditText hhClock_Edit = (EditText) findViewById(R.id.clockHours_Edit);
    final EditText mmClock_Edit = (EditText) findViewById(R.id.clockMins_Edit);

    higherNumber_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(courseCredits_Edit.getText().toString());
            ++a;
            courseCredits_Edit.setText(a + "");
        }
    });

    lowerNumber_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(courseCredits_Edit.getText().toString());
            --a;
            courseCredits_Edit.setText(a + "");
        }
    });

    higherClasshh_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(hhClass_Edit.getText().toString());
            ++a;
            hhClass_Edit.setText(a + "");
        }
    });

    lowerClasshh_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(hhClass_Edit.getText().toString());
            --a;
            hhClass_Edit.setText(a + "");
        }
    });

    higherClassmm_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(mmClass_Edit.getText().toString());
            ++a;
            mmClass_Edit.setText(a + "");
        }
    });

    lowerClassmm_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(mmClass_Edit.getText().toString());
            --a;
            mmClass_Edit.setText(a + "");
        }
    });

    higherClockhh_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(hhClock_Edit.getText().toString());
            ++a;
            hhClock_Edit.setText(a + "");
        }
    });

    lowerClockhh_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(hhClock_Edit.getText().toString());
            --a;
            hhClock_Edit.setText(a + "");
        }
    });

    higherClockmm_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(mmClock_Edit.getText().toString());
            ++a;
            mmClock_Edit.setText(a + "");
        }
    });

    lowerClockmm_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            int a = Integer.parseInt(mmClock_Edit.getText().toString());
            --a;
            mmClock_Edit.setText(a + "");
        }
    });

    save_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks

        }
    });

    cancel_Button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            finish();
        }
    });
}

}`

  • 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-27T03:14:10+00:00Added an answer on May 27, 2026 at 3:14 am

    1) use the “tag” property of each one of your button in your xml layout.

    http://developer.android.com/reference/android/view/View.html

    Tags

    Unlike IDs, tags are not used to identify views. Tags are essentially
    an extra piece of information that can be associated with a view. They
    are most often used as a convenience to store data related to views in
    the views themselves rather than by putting them in a separate
    structure.

    2) use also onclick in your xml

     <Button
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:tag="1"
         android:onClick="doSomething" />
    

    in your code:

    public void doSomething(View v){
        int tag=v.getTag();
        //Do something smart with button, like odd numbers = plus and even = minus.
    }
    

    http://developer.android.com/reference/android/view/View.html#getTag()

    If you want to programmaticaly, with the code above, get the corresponding edittext, just store their ID in an arraylist and play with the int to get the corresponding EditText.

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

Sidebar

Related Questions

I have a custom dialog with one editText view and two buttons ok and
I have two EditTexts in XML. In one EditText, the user can put a
I have one activity Select which has four buttons and other activity Result. Now
I have an EditText and a Button set next to each other on the
I have a bunch of EditTexts in my Android application, each with InputMethod set
I have a custom table cell which basically has 2 buttons, one textview and
I have a layout where I have some edittexts and one button. This button
I want to have Buttons next to each other on the same line, and
I'm new in android and i have created editText dynamically with the following code
I have a custom listView with editText in each row to carry value entered

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.