На кнопку Слушатель вызывается дважды

Я знаю, что это легко, но я м просто не в состоянии его отладки.

Я динамически создавать 3 LinearLayouts и добавление их в спиральном View. Я добавляю кнопку «плюсы» в верхнюю части 3 LinearLayout.

Проблема заключается в том, что по нажатию кнопки Ins, его на clicklistener вызывается 3 раза. Код:

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();


            }

        }
    }






}

Я знаю, что, безусловно, есть некоторые проблемы в коде OnCreate, но что это такое? Помогите пожалуйста

Может кто-нибудь объяснить, кроме того, как установить кнопку выровненную о праве экрана, то есть, как установить его макет гравитацию?

7
задан kumar piyush 8 June 2012 в 06:44
поделиться