gpt4 book ai didi

java - Eclipse 和 Android Activity 中的错误似乎无法弄清楚

转载 作者:行者123 更新时间:2023-12-01 15:57:42 26 4
gpt4 key购买 nike

我在尝试实现几个 OnLongClick 按钮时不断遇到错误。 Eclipse 一直告诉我“添加未实现的方法”。我对开发非常陌生,我正在寻求一些帮助。 :D 我在这里做错了什么?这个社区以前帮助过我,一旦我到达可以回馈的地方,我就会回馈。我为此感谢大家。这是我正在开发的一个简单应用程序的代码。

    package com.kc.eas;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageButton;
import android.widget.RemoteViews.ActionException;
import android.widget.Toast;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;

import com.admob.android.ads.AdManager;
import com.admob.android.ads.AdView;

public class act2 extends Activity implements OnClickListener, OnLongClickListener {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

AdManager.setTestDevices(new String[] {
AdManager.TEST_EMULATOR,
"HT089HL01612",
});

AdView adView = (AdView)findViewById(R.id.ad);
adView.requestFreshAd();



ImageButton batteryhistory = (ImageButton) findViewById(R.id.battery_history);
manageservices.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent batteryhistoryintent = new Intent();
batteryhistoryintent.setAction(Intent.ACTION_MAIN);
batteryhistoryintent.setClassName("com.android.settings","com.android.settings.battery_history.BatteryHistory");
startActivity(batteryhistoryintent);

ImageButton batteryusage = (ImageButton) findViewById(R.id.battery_usage);
manageservices.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent batteryusageintent = new Intent();
batteryusageintent.setAction(Intent.ACTION_MAIN);
batteryusageintent.setClassName("com.android.settings","com.android.settings.fuelgauge.PowerUsageSummary");
startActivity(batteryusageintent);

ImageButton batteryinfo = (ImageButton) findViewById(R.id.battery_info);
batteryinfo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent batteryinfointent = new Intent();
batteryinfointent.setAction(Intent.ACTION_MAIN);
batteryinfointent.setClassName("com.android.settings","com.android.settings.BatteryInfo");
startActivity(batteryinfointent);

ImageButton manageapps = (ImageButton) findViewById(R.id.manage_apps);
manageapps.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent manageappsintent = new Intent();
manageappsintent.setAction(Intent.ACTION_MAIN);
manageappsintent.setClassName("com.android.settings","com.android.settings.ManageApplications");
startActivity(manageappsintent);

ImageButton manageservices = (ImageButton) findViewById(R.id.manage_services);
manageservices.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent manageservicesintent = new Intent();
manageservicesintent.setAction(Intent.ACTION_MAIN);
manageservicesintent.setClassName("com.android.settings","com.android.settings.RunningServices");
startActivity(manageservicesintent);

ImageButton radioinfo = (ImageButton) findViewById(R.id.radio_info);
radioinfo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent radioinfointent = new Intent();
radioinfointent.setAction(Intent.ACTION_MAIN);
radioinfointent.setClassName("com.android.settings","com.android.settings.RadioInfo");
startActivity(radioinfointent);


private WifiManager wifiManager;



ImageButton startwifiButton = (ImageButton) findViewById(R.id.wifi);
startwifiButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
WifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()){
WifiManager.setWifiEnabled(false);
Context context = getApplicationContext();
CharSequence text = "Disabling WiFi";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

}else{
WifiManager.setWifiEnabled(true);
Context context = getApplicationContext();
CharSequence text = "Enabling WiFi";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}

private BluetoothAdapter bluetoothAdapter;


ImageButton bluetoothbutton = (ImageButton) findViewById(R.id.bluetooth);
bluetoothbutton.setOnClickListener(new View.OnClickListener(){
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
{

if (enabled) {
bluetoothAdapter.enable();

} else {
bluetoothAdapter.disable();
}


//OnLongClickButtons//



ImageButton bluetoothbutton = (ImageButton) findViewById(R.id.bluetooth);
bluetoothbutton.setOnLongClickListener(new View.OnLongClickListener(){
public void onLongClick(View v) {
Intent btintent = new Intent();
btintent.setAction(Intent.ACTION_MAIN);
btintent.setClassName("com.android.settings","com.android.settings.bluetooth.BluetoothSettings");
startActivity(btintent);

ImageButton wifisettings = (ImageButton) findViewById(R.id.wifi);
wifisettings.setOnLongClickListener(new View.OnLongClickListener() {
public void onLongClick(View v) {
Intent manageservicesintent = new Intent();
manageservicesintent.setAction(Intent.ACTION_MAIN);
manageservicesintent.setClassName("com.android.settings","com.android.settings.wifi.WifiSettings");
startActivity(manageservicesintent);
}
});
}
}

public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}

public void onClick(View v) {
// TODO Auto-generated method stub

}

最佳答案

将鼠标悬停在类名称上

然后点击“添加未实现的方法”,如下所示

alt text

错误的原因是您使用了一些抽象类,并且有必要为已实现的类中未实现的方法提供主体

关于java - Eclipse 和 Android Activity 中的错误似乎无法弄清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4778253/

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