根据你这样写有问题,我不知道我写的对不对 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)
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.activity_main, this); 这2句报错,错误信息是The method inflate(int, ViewGroup) in the type LayoutInflater is not applicable for the arguments (int) 这方法我试过,但折腾不出来。。
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 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,这样应该就可以用了。
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,这样应该就可以用了。