设置动态创建的EditText文字的Andr​​oid?文字、动态、oid、EditText

2023-09-07 11:12:52 作者:捂着心脏〞逞强的笑

海是android系统中我创建了一个动态的按钮和编辑文本创造新的我有两个进入多少按钮和编辑文本应创建1页。 (在页面IHAVE只有一个编辑文本并提交按钮,如果我进入3。三的EditText和3个按钮,将在下一个页面上创建动态的),如果我preSS三个下一页将是像三个按钮和三个的EditText

hai am new in android i have created a dynamically button and edit text creation i have two pages 1 for entering how many button and edit text should be created. (in that page ihave only one edit text filed and button if i enter 3 .three edittext and 3 button will create on next page dynamically) if i press three the next page will be like three button and three edittext

我要对pressing第一编辑文本打印你好输入ur1st时间按钮但是当我preSS该按钮的值将被打印在第三的EditText结果在code以下

i have want to print hello on the first edit text on pressing enter ur1st time button but when i press that button the value is printed on the third edittext the code is given below

package a.l;


   public class dyna extends Activity {
TextView t1;
Button btn;
EditText edt;
int i,j,t = 0,mHour,mMinute,count=0,mDate,mYear,mMonth;
Button b;
Toast mToast;
ScrollView sv;
Calendar c = Calendar.getInstance();
SQLiteDatabase myDB ; 
PendingIntent sender;
AlarmManager am;
Intent intent;
int alarmtype;
long timeinmilli;



protected static final int TIME_DIALOG_ID = 1;
 private static final int DATE_DIALOG_ID = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dyna);
t1 = (TextView)findViewById(R.id.textdyna);


 mHour = c.get(Calendar.HOUR_OF_DAY);
 mMinute = c.get(Calendar.MINUTE);
 mDate=c.get(Calendar.DATE);
 mMonth=c.get(Calendar.MONTH);
 mYear=c.get(Calendar.YEAR);
 String date=mDate+"/"+mMonth+"/"+mYear;
 count=1;



        Bundle bu =  getIntent().getExtras();
        String s1 = bu.getString("5");
        int i1=Integer.parseInt(s1);
        String s2 = bu.getString("3");
        String s3 = bu.getString("4");




//  if(date.equals(s2)){     
        sv = new ScrollView(this);
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setBackgroundResource(R.drawable.vec);


        sv.addView(ll);

        for(i = 1; i <i1+1; i++)
        {
           b = new Button(this);

           b.setText(" enter ur"+ i +"st time");
           b.setId(i); 
           b.setTextSize(10);
           b.setPadding(8,3,8,3);   
           b.setTextColor(Color.DKGRAY);
           b.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);     
           b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));        


           c.setTimeInMillis(System.currentTimeMillis());
            c.add(Calendar.SECOND,10);
            alarmtype=AlarmManager.RTC_WAKEUP;
            timeinmilli= c.getTimeInMillis();
           intent = new Intent(dyna.this, MyAlarmReceiver.class);
           sender = PendingIntent.getBroadcast(dyna.this,0, intent, 0);
           am = (AlarmManager)getSystemService(ALARM_SERVICE);



           edt=new EditText(this);
           edt.setId(i);
           edt.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));





           ll.addView(b);
           ll.addView(edt);
           System.out.println("am on");

           b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int a=edt.getId();
                    int bh=b.getId();





                    //showDialog(TIME_DIALOG_ID);

                System.out.println("am on button");    

                        // We want the alarm to go off 10 seconds from now.


                      // c.add(Calendar.MINUTE,mMinute);


                        // Schedule the alarm!

   //                           am.set(alarmtype,timeinmilli, sender);
   //
  //                       
   //                           // Tell the user about what we did.
  //                            if (mToast != null) {
  //                                mToast.cancel();
  //                            }
  //                            mToast = Toast.makeText(dyna.this,"Alarm    Started on"+i,Toast.LENGTH_LONG);
  //                            mToast.show();
   //       
                       }
            });



        }



        this.setContentView(sv);    

//  }
  //      do it for ending alarm at this date
   ////   
   //////     if(date.equals(s3))
  ////////  {
  //////          
 ////     }
  //      

}

 private TimePickerDialog.OnTimeSetListener mTimeSetListener =
        new TimePickerDialog.OnTimeSetListener() {
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                mHour = hourOfDay;
                mMinute = minute;


            }


        };
        protected Dialog onCreateDialog(int id) {
            // TODO Auto-generated method stub
            switch (id) {


             case TIME_DIALOG_ID:
                return new TimePickerDialog(this,
                         mTimeSetListener, mHour, mMinute, false);


                        }
            return null;
        }
}

在code现在用的就是给出,请找到一个解决方案谢谢

the code am using is given please find a solution thank you

推荐答案

试试这个code

package com.openxcell.DemoAnimation;

import java.util.ArrayList;
import java.util.List;

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;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class **DynamicEditText** extends Activity implements OnClickListener {

    ArrayList<Integer> _ArrListScpoe = new ArrayList<Integer>();
    // List<EditText> allEds = new ArrayList<EditText>();
    List<Button> allbtn = new ArrayList<Button>();
    RelativeLayout.LayoutParams ParaOne;
    EditText EtScopeDYN, EtBidDYN;
    Button btnDynamic, btnDynamicOne, btnOne;
    int _intClick = 0, _intClickBid = 0;
    LinearLayout LLAdd, LLDynamic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edittext);
        LLAdd = (LinearLayout) findViewById(R.id.LLAdd);
        LLAdd.setOrientation(LinearLayout.VERTICAL);

        btnOne = (Button) findViewById(R.id.button1);
        btnOne.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                DynamicEditScope();
            }
        });
    }

    public void DynamicEditScope() {
        ParaOne = new RelativeLayout.LayoutParams(120, 40);
        EtScopeDYN = new EditText(DynamicEditText.this);
        LLDynamic = new LinearLayout(DynamicEditText.this);
        btnDynamic = new Button(DynamicEditText.this);

        EtScopeDYN.setId(_intClick);
        // allEds.add(EtScopeDYN);
        EtScopeDYN.setTextSize(12);
        ParaOne.topMargin = 5;
        ParaOne.leftMargin = 55;

        btnDynamic.setText("Add" + _intClick);
        btnDynamic.setId(_intClick);
        allbtn.add(btnDynamic);
        btnDynamic.setOnClickListener(this);

        LLDynamic.addView(EtScopeDYN, ParaOne);
        LLDynamic.addView(btnDynamic, ParaOne);
        LLDynamic.setOrientation(LinearLayout.HORIZONTAL);

        LLAdd.addView(LLDynamic);
        _ArrListScpoe.add(_intClick);
        _intClick++;
    }

    public void onClick(View v) {
        for (int i = 0; i < _ArrListScpoe.size(); i++) {
            if (v.getId() == i) {
                EtBidDYN = (EditText) findViewById(_ArrListScpoe.get(i));
                EtBidDYN.setText(allbtn.get(i).getText().toString());
            }

        }

    }

}