开发者

getID for button returns -1

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜