这样么
Button lb=(Button)findViewById(R.id.button1);
Button lb=(Button)findViewById(R.id.button1);
解决方案 »
- xmppconnection中login登陆问题
- 想在TabHost下嵌套一个listview该怎么做
- android中使用libgdx 加入重力感应的问题 高手请进
- 找android programmer
- 请教个初级问题,环境搭建
- activity 转向中间出现黑屏.一会儿就好了。
- 垂直滚动的TEXTVIEW文本
- 如何使用Handler实现主线程往子线程传递消息
- android网络连接问题,android.os.NetworkOnMainThreadException异常
- 跪求Mars第二季重制版视频
- android 4.4 下播放视频只有声音无图像
- 小白问题,在线等。游戏信息保存,不被用户删除
setContentView(R.layout.你画面的xml);
Button btn = (Button)view.findViewById(id);
MainActivity
setContentView(R.layout.activity_main);
GameView
public class GameView extends View
{
public GameView(Context context, AttributeSet attrs)
{
super(context, attrs);
Button button = (Button)findViewById(R.id.button1);
System.out.println(button);//输出是null
}
}
XMLactivity_main
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/view1"
android:layout_marginLeft="96dp"
android:layout_marginTop="73dp"
android:text="Button" /> <view
android:id="@+id/view1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button1"
android:layout_marginRight="23dp"
android:layout_marginTop="65dp"
class="com.example.testview.GameView" />
View view = LayoutInflater.from(context).inflate(R.layout.activity_main,null);
Button button = (Button)findViewById(R.id.button1);
System.out.println(button);
错误提示:The method inflate(int, ViewGroup) in the type LayoutInflater is not applicable for the arguments (int)
我上面说的报错是指View view = LayoutInflater.from(context).inflate(R.layout.activity_main,null);这行
源码我上面贴出来了,求帮忙看看。
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.xmlactivity_main, this);
Button button = (Button)findViewById(R.id.button1);
System.out.println(button);看看这样有用吗?
inflater.inflate(R.layout.activity_main, this);
这2句报错,错误信息是The method inflate(int, ViewGroup) in the type LayoutInflater is not applicable for the arguments (int)
这方法我试过,但折腾不出来。。
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.xmlactivity_main, this);
Button button = (Button)view.findViewById(R.id.button1);
System.out.println(button);
inflater.inflate(R.layout.activity_main, this);
这2句报错,错误信息是The method inflate(int, ViewGroup) in the type LayoutInflater is not applicable for the arguments (int)
这方法我试过,但折腾不出来。。如果可以,我觉得可以让GameView继承linearlayout,这样应该就可以用了。