Android의 다른 클래스에서 보유한 메소드를 호출하려고합니다. 난 그냥 안드로이드 개발 오늘 시작 했어 그래서 이것은 나에게 모두 새로운 것입니다. 내가 원하는 것은 단추를 클릭하여 코드를 실행하는 것입니다.Android 및 Java 유형을 확인할 수 없습니다.
그러나 버튼 코드에는 IDE에서 유형을 확인할 수 없다고 알려주는 문제가 있습니다. 누구든지이 문제를 해결할 수 있도록 도와 줄 수 있습니까?
다음 내 주요 활동 수업.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button aButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListeners();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void addListeners() {
Button btnCallMethod = (Button) this.findViewById(R.id.btnCallMethod);
// CALL METHOD BUTTON
btnCallMethod.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
// error is on this line below
Intent intent = new Intent(getApplicationContext(), DeviceScanActivity.class);
startActivity(intent); // start the DeciveScanActivity
}
return false;
}
});
}
}
업데이트 내 DeviceScanActivity 클래스의 코드 :
import android.annotation.TargetApi;
import android.app.ListActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ArrayAdapter;
@TargetApi(18)
public class DeviceScanActivity extends ListActivity {
private Handler mHandler;
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
private ArrayAdapter<Object> list;
protected void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
int key = b.getInt("yourKey");
switch(key)
{
case 1: // call method here
list = new ArrayAdapter<Object>(getApplicationContext(),
android.R.layout.simple_list_item_1);
setListAdapter(list);
scanLeDevice(true);
}
}
@TargetApi(18)
public void scanLeDevice(final boolean enable) {
list.add("Scanning...");
final BluetoothAdapter adapter = getBluetoothAdapter();
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// mBluetoothAdapter.stopLeScan(mLeScanCallback);
adapter.stopLeScan(callback);
list.clear();
}
}, SCAN_PERIOD);
adapter.startLeScan(callback);
} else {
adapter.stopLeScan(callback);
}
}
@TargetApi(18)
private BluetoothAdapter getBluetoothAdapter()
{
BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
return manager.getAdapter();
}
private final BluetoothAdapter.LeScanCallback callback = new BluetoothAdapter.LeScanCallback()
{
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
// TODO Auto-generated method stub
{
list.add("found: " + device);
runOnUiThread(new Runnable(){
@Override
public void run()
{
list.add(device);
list.notifyDataSetChanged();
}
});
}
}
};
}
이 또한 내가 생각하는 내 매니페스트 XML은 안드로이드에 대한 중요하다
<?xml version="1.0" encoding="utf-8"?>
오류는 곳이다
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.bletest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
어떤 IDE를 사용하고 있습니까? Android SDK가 설치되어 있고 IDE가 Android를 인식하도록 설정되어 있습니까? – hexafraction
Ecplise. 안드로이드 SDK를 다운로드하여 거기에서 실행했습니다. 내가 읽은 것부터 자동 완성되어야합니다. 내 헬륨 앱이 내 기기에서 제대로 작동하도록 할 수 있습니다. – N0xus
logcat을 붙여주세요. –