gpt4 book ai didi

android - 错误 R.id.togglebutton1 等

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:03 26 4
gpt4 key购买 nike

package com.example.hello.word;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;

public class OptionsMenu extends Activity{

MediaPlayer ourSong;
Button btn1;
Intent openStartingPoint;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menuoptions);

final ToggleButton onTog = (ToggleButton) findViewById(R.id.toggleButton1);
onTog.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
if (onTog.isChecked()){
ourSong.start();
}else{
ourSong.stop();
}
}
});

我在所有按钮下都有一个错误,它向我显示例如:“菜单选项无法解析或不是字段”。在 togglebutton1 上出现相同的错误

我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Volume"
android:textSize="40dp"
android:textStyle="bold"
android:layout_marginTop="40dp"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="121dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="ToggleButton" />

<Button
android:id="@+id/button1"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:text="Back" />

</LinearLayout>

我试图清理项目.. 删除 R 类和所有内容!我能做些什么来解决这个错误?感谢帮助者..

最佳答案

您收到该错误是因为您正在导入 android.R 您必须删除此导入。

尝试从您的代码中删除 import android.R; 行,这应该可以解决您的问题

当您按 control + shift + O 在 eclipse 中组织您的导入时,它有时会添加 android.R 的导入

这里有一个类似的问题

关于android - 错误 R.id.togglebutton1 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13368925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com