Note that there are some explanatory texts on larger screens.

plurals
  1. POOn click Listener called twice
    primarykey
    data
    text
    <p>I know this is easy but i m just not able to debug it.</p> <p>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. </p> <p>The problem is that on clicking the ins Button , its on clicklistener is being called 3 times . code:</p> <pre><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&lt;3;i++){ for(int j =0;j&lt;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&lt;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(); } } } } </code></pre> <p>I know definitely , there is some problem in the code of OnCreate but what it is ? Help please</p> <p>Can anyone further explain how to set the button aligned o the right of screen , that is how to set its layout gravity?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload