Errors in Eclipse and Android activity can't seem to figure it
I keep getting errors trying to implement a couple of OnLongClick buttons. Eclipse keeps telling me to "add unimplemented methods". I'm very new to developing and I'm asking for some help. :D What am I doing wrong here? This community helped me out before and as soon as I get to where I can give back I will. I thank you all for it. Here's my code for a simple app I'm working on.
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(){
Bluetoot开发者_如何学ChAdapter 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
}
Go and hover over the class name
and click "Add unimplemented methods", like shown below
The reason for the error is that you have used some abstract classes, and its a necessary obligation to give a body to the unimplemented methods from the implemented classes
精彩评论