无法在 startActivityForResult 中识别 int?
Can't identify int in startActivityForResult?
包 com.example.feelhut;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class editprofile extends AppCompatActivity {
ImageButton proileimagebutton;
private static final int ImageRequest=1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("imageeeeeee/");
ImageRequest 在 startActivityForResult 中显示错误。意味着我无法在此处识别图像请求。
startActivityForResult(intent.ImageRequest);
}
});
}
}
您需要在“public class editprofile extends AppCompatActivity”上方声明int。
代码应该是
private ImageButton proileimagebutton;
private static final int ImageRequest=1;
public class editprofile 扩展 AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("imageeeeeee/");
public class editprofile extends AppCompatActivity {
ImageButton proileimagebutton;
private static final int ImageRequest=1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//no content view? add like this setContentView(R.layout.yourViewLayout);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent,ImageRequest);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ImageRequest&& resultCode == RESULT_OK) {
// your ImageView.setUri(data.getData();
}
}
}
包 com.example.feelhut;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class editprofile extends AppCompatActivity {
ImageButton proileimagebutton;
private static final int ImageRequest=1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("imageeeeeee/");
ImageRequest 在 startActivityForResult 中显示错误。意味着我无法在此处识别图像请求。
startActivityForResult(intent.ImageRequest);
}
});
}
}
您需要在“public class editprofile extends AppCompatActivity”上方声明int。 代码应该是
private ImageButton proileimagebutton;
private static final int ImageRequest=1;
public class editprofile 扩展 AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("imageeeeeee/");
public class editprofile extends AppCompatActivity {
ImageButton proileimagebutton;
private static final int ImageRequest=1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//no content view? add like this setContentView(R.layout.yourViewLayout);
proileimagebutton= findViewById(R.id.edit_profile);
proileimagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent,ImageRequest);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ImageRequest&& resultCode == RESULT_OK) {
// your ImageView.setUri(data.getData();
}
}
}