我想創建一個按鈕,點擊後它會顯示另一個意圖。setOnClickListener錯誤 - 無法解析符號
這是代碼:
<Button
android:text="Bine ati venit!"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button1"
android:background="#479fc7"
android:textSize="40dp"
android:textColor="@color/colorPrimaryDark"
android:textStyle="normal|bold|italic"
android:textAllCaps="false"
android:fontFamily="casual"
android:onClick="next_page"/>
,並從的.java類:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
}
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick (View v){
next_page(v);
}
});
public void next_page(View v) {
Intent intent = new Intent(this, MapsActivity.class);
startActivity(intent);
}
我得到的錯誤: 「無法解析符號 'setOnClickListener'」,「可變的onClick是永遠使用「,」;預計「....
你爲什麼不把'onCreate'方法中的'button'? –
你已經在你的xml文件中設置了標籤android:onClick =「next_page」,所以你可以刪除你的Button init,它的onClickListener –
哦,我沒有看到...... thx! – rocko