Reputation: 459
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button b = new Button(this);
String id = Integer.toString(b.getId());
Toast.makeText(getApplicationContext(), id, 1).show();
}
}
Why does it return -1?
Upvotes: 0
Views: 1029
Reputation: 3412
Because that's the ID views are given when you create them yourself.
Just set the ID with
b.setId(int)
http://developer.android.com/reference/android/widget/Button.html
Upvotes: 3