如何将Android SDK源附加到Android Studio?
当我打开其中一个Android类时,不会出现带有"附加源"选项的"未找到源"窗口.
另外一种方法是什么?
我有一个扩展Fragment的第一个类,以及扩展Activity的第二个类.
我的片段工作正常,片段中的Intent代码是:
ImageButton button= (ImageButton) getView().findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(MyFragment.this, MyClass.class);
MyFragment.this.startActivity(myIntent); }
});
Run Code Online (Sandbox Code Playgroud)
我的MyClass类代码是:
public class MyClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The activity is being created.
}
@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.MyClass);
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
Gradle: cannot find symbol constructor Intent(com.xxxx.xxxx.MyFragment,java.lang.Class<com.xxxx.xxxx.MyClass>)
我不知道哪里出错了.
在Android Studio 2.1中我使用API 24就好了,然后突然开始在我的AndroidManifest.xml中看到"找不到Android API 24平台的源代码"警告.
在Android Studio中重新运行Android SDK Manager设置,删除其他不受支持的API 等对我来说不起作用.我该如何解决?
我有这个成绩档案:
//ext.support_library_version = '24.0.0'
android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
applicationId "---"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
...
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试打开任何与Android相关的类时,它说我没有api24的来源,即使buildToolsVersion '24.0.0'安装了它.知道为什么吗?
我必须将参数从MyActivity.class传递给TestService.class.MyActivity是一个Activity类,TestService是我用来发送消息的服务.我必须将参数从Activity传递给Service,但是当我Intent i = getIntent();在服务类中调用时,我得到一个错误getIntent()是未定义的.
那么,如何将参数从我的Activity发送到服务?
我是Android开发的新手,在改变活动时遇到了一些问题.我试图从一个方法中改变活动,但我收到错误,cannot resolve method startActivity并在参数结束时出错Cannot resolve constructor 'Intent (...)'.我在这里发现了一个同样问题的问题,并试图将他们的回复实施到我的程序中但没有快乐.
这是代码:
public void open301(View view) {
startActivity(new Intent(CustomAdapter.this, ThreeZeroOne.class));
}
Run Code Online (Sandbox Code Playgroud)
在查看上面链接的问题的回复之前,代码看起来像这样,具有相同的错误:
public void open301(View view) {
Intent openThree = new Intent(this,ThreeZeroOne.class);
startActivity(openThree);
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;
public class CustomAdapter extends BaseAdapter {
String[] result;
Context context;
int[] imageId;
private static LayoutInflater inflater = null;
public CustomAdapter(selectGame …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个打开不同活动的简单按钮:
package com.example.xxx.buttonexample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick();
}
public void btnClick() {
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Intent intent = new Intent(this,emergencyIntent.class);
startActivity(intent);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的emergencyIntent.class文件:
package com.example.xxx.buttonexample;
import android.app.Activity;
import android.os.Bundle;
public class emergencyIntent extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud)