0

I want to create a view which has one button that add edit text and button to the view. now how can i set the id to view so that i could also remove the view.

Lalit Chattar
  • 1,914
  • 8
  • 27
  • 49

3 Answers3

0

when u create the dynamic button then only to set and get id from that like..

int count = 0;

Button mbutton = new Button(getapplicationcontext());

mbutton.setId(count);

count++;

when u want to perform the any action u want to get id from that like..

mbutton.getId();

0

whatever control you set I don't know but you can set the id of the control like this way

Button b; // if you want to set button and set the id 
b.setId(1);

View v;
v.setId(2);

or any control provide unique integer value

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • How can i save this id for removing view? – Lalit Chattar Oct 18 '11 at 10:45
  • did you more explain how you can using your view? like multiple time or at specific time and why you want keep this id if the view was fixed and also id – Pratik Oct 18 '11 at 10:48
  • You can see the android default Contact Manager Application in which when we add new contact then it display a view for specifying phone type. i want to implement the same. – Lalit Chattar Oct 18 '11 at 10:51
0

You can use setId() function of View class which is inherited to most of views like TextView,Button...etc.

Android Killer
  • 18,174
  • 13
  • 67
  • 90