我怎样才能在java代码中创建一个Button [英] how can i creat a Button in java Code
本文介绍了我怎样才能在java代码中创建一个Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
按钮B =新按钮(这个);
B.setText =do!;
当我运行我的应用程序时,我看不到设备中的任何按钮!
解决方案
你需要做类似的事情:
按钮myButton = new 按钮(此);
myButton.setText( Click Me!);
LinearLayout ln =(LinearLayout)findViewById(R.id.buttonlayout);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
ln.addView(myButton,lp);
参见http://docs.oracle.com/javase/tutorial/uiswing/index.html [ ^ ]。
hi everyone . i want to create a Button in my android app
this is my code :
Button B=new Button(this);
B.setText="do!";
when i run my app i cant see any Button in my device!
解决方案
You need to do something like:
Button myButton = new Button(this); myButton.setText("Click Me!"); LinearLayout ln = (LinearLayout)findViewById(R.id.buttonlayout); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); ln.addView(myButton, lp);
See http://docs.oracle.com/javase/tutorial/uiswing/index.html[^].
这篇关于我怎样才能在java代码中创建一个Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文