public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
开发者_如何学Python Button b = new Button(this);
String id = Integer.toString(b.getId());
Toast.makeText(getApplicationContext(), id, 1).show();
}
}
Why does it return -1?
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
精彩评论