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
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;
}
}
the code am using is given please find a solution thank you
Try this code
Create separate arrays for
Button
andEditText
...so that it will be easy for you to identify. Also, I can see that you are setting the same id to bothButton
andEditText
.Inside array, just initialize your arrays and inside the
setOnClickListener
for yourButton
, set the correspondingEditText