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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:31:59+00:00 2026-06-05T18:31:59+00:00

I know this is easy but i m just not able to debug it.

  • 0

I know this is easy but i m just not able to debug it.

I am dynamically creating 3 LinearLayouts and adding them to a scroll View . I am adding a Button “ins” to the top of 3 linearlayout.

The problem is that on clicking the ins Button , its on clicklistener is being called 3 times .
code:

package com.integrated.mpr;

import android.app.Activity;
import android.app.Dialog;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;


public class Page1 extends Activity implements OnClickListener{

    static int pos = new Choose().n;
    static String partname;

    int i;
    int[][] id = new int[pos][5];


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        int p =0;
        for(int i =0;i<3;i++){
            for(int j =0;j<5;j++){

                p++;
            }
        }


        ScrollView sv = new ScrollView(this);

        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        int resid = getResources().getIdentifier("background", "drawable", getPackageName());
        ll.setBackgroundResource(resid);

        Button ins = new Button(this);
        ins.setText("Instructions");
        ins.setOnClickListener(this);
        ins.setId(5000);

        ll.addView(ins);

        for(i =0;i<3;i++){


            LinearLayout llay = new LinearLayout(this);
            llay.setOrientation(LinearLayout.VERTICAL);

            TextView tv = new TextView(this);
            tv.setText("enter the " +(i+1)+" position name");


            EditText et = new EditText(this);
            et.setId(id[i][0]);

            Button starta = new Button(this);
            starta.setText("Record 1");
            starta.setId(id[i][1]);
            starta.setOnClickListener(this);

            Button startb = new Button(this);
            startb.setText("Record 2");
            startb.setId(id[i][2]);
            startb.setOnClickListener(this);


            Button startc = new Button(this);
            startc.setText("Record 3");
            startc.setId(id[i][3]);
            startc.setOnClickListener(this);


            Button stop = new Button(this);
            stop.setText("Submit");
            stop.setId(id[i][4]);
            stop.setOnClickListener(this);

            TextView tv1 = new TextView(this);
            tv1.setVisibility(llay.INVISIBLE);

            llay.addView(tv);
            llay.addView(et);
            llay.addView(starta);
            llay.addView(startb);
            llay.addView(startc);
            llay.addView(stop);
            llay.addView(tv1);
            ll.addView(llay);

        }
        Button bcon = new Button(this);
        bcon.setText("Continue");
        bcon.setId(10000);
        bcon.setOnClickListener(this);
        ll.addView(bcon);


        sv.addView(ll);

        this.setContentView(sv);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

            if(v.getId()==5000){    
            Log.d("ins", "called");
            Context mContext = Page1.this;
            Dialog dialog = new Dialog(mContext);
            dialog.setTitle("Instructions");
            dialog.setContentView(R.layout.instructiondialog);
            dialog.show();


            }

        }
    }






}

I know definitely , there is some problem in the code of OnCreate but what it is ? Help please

Can anyone further explain how to set the button aligned o the right of screen , that is how to set its layout gravity?

  • 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-05T18:32:01+00:00Added an answer on June 5, 2026 at 6:32 pm

    I am not sure about what exactly you want to achieve.but you can set the flag.if flag value is 1 then only process onClick else not.

    Below snippet will help you.

    Yes but you will have to somehow reset that flag to 1.

        @Override
            public void onClick(View v) 
               {
                // TODO Auto-generated method stub
    
                    if(v.getId()==5000)
                    {    
                    if(flag)
                     {
                       Log.d("ins", "called");
                       Context mContext = Page1.this;
                       Dialog dialog = new Dialog(mContext);
                       dialog.setTitle("Instructions");
                       dialog.setContentView(R.layout.instructiondialog);
                       dialog.show();
                     }
                    flag=0;
                    }
                 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this should be easy but it's just not my day today. I
I know this is something easy but I just can't see it. Can anyone
I know this is easy enough just removing the f.label, but then it changes
sorry - I know this is dead easy stuff, but I'm just trying to
I know this is an easy question but I can't figure it out or
I know this is kind of easy question but i cant seem to find
I know this is probably super easy, but I'm having a hard time wading
This should be very easy but I don't know how to do it. I
There must be a very easy way to do this but I don't know
I know this is quite easy trigonomety, however I was never introducted to vectors

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.