Eclipse和Android活动中的错误似乎无法解决

时间:2011-01-24 03:10:28

标签: java android eclipse compiler-construction

我一直在尝试实现几个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

        }

1 个答案:

答案 0 :(得分:1)

转到并将鼠标悬停在班级名称

并单击“添加未实现的方法”,如下所示

alt text

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