Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将图像从窗体加载到RecyclerView_Java_Android - Fatal编程技术网

Java 将图像从窗体加载到RecyclerView

Java 将图像从窗体加载到RecyclerView,java,android,Java,Android,我正在将图片从表单上传到回收视图。我的创作方式是,如果我点击“+”按钮,让我放置它,让我放置一张画廊图片,或者从相机中拍摄 但除此之外,对于微调器,我已经为他指定了列表中的每个元素默认为他指定了一个图像,我已经通过Glide加载了该图像: spTypePets.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelect

我正在将图片从表单上传到回收视图。我的创作方式是,如果我点击“+”按钮,让我放置它,让我放置一张画廊图片,或者从相机中拍摄

但除此之外,对于微调器,我已经为他指定了列表中的每个元素默认为他指定了一个图像,我已经通过Glide加载了该图像:

spTypePets.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        Resources res = getResources();
        String spinner = spTypePets.getSelectedItem().toString();

        switch (position) {

            case 0:

                Glide.with(PetsFormActivity.this).load(R.drawable.dog).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 1:

                Glide.with(PetsFormActivity.this).load(R.drawable.cat).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 2:

                Glide.with(PetsFormActivity.this).load(R.drawable.mouse).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 3:

                Glide.with(PetsFormActivity.this).load(R.drawable.fish).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 4:

                Glide.with(PetsFormActivity.this).load(R.drawable.birds).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 5:

                Glide.with(PetsFormActivity.this).load(R.drawable.reptile).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

            case 6:

                Glide.with(PetsFormActivity.this).load(R.drawable.other).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;

        }

    }
我知道,除了保存滑翔外,我还必须将它保存在“宠物”中,以便添加,但我不知道如何添加。看看你能不能帮我一把。多谢各位


问候。

首先需要将
R.drawable
转换为
String
,然后将其分配给
imagePath

示例

spTypePets.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        Resources res = getResources();
        String spinner = spTypePets.getSelectedItem().toString();

        switch (position) {
            case 0:
              imagePath = getURLForResource(R.drawable.dog);
              Glide.with(PetsFormActivity.this).load(R.drawable.dog).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;
                     ......
            }   
      }

public String getURLForResource (int resourceId) {
    return Uri.parse("android.resource://"+R.class.getPackage().getName()+"/" +resourceId).toString();
 }
sptypets.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
Resources res=getResources();
字符串微调器=spTypePets.getSelectedItem().toString();
开关(位置){
案例0:
imagePath=getURLForResource(R.drawable.dog);
Glide.with(PetsFormActivity.this).load(R.drawable.dog).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
打破
......
}   
}
公共字符串getURLForResource(int resourceId){
返回Uri.parse(“android.resource://”+R.class.getPackage().getName()+“/”+resourceId.toString();
}

单击
btnSave
时,检查
imagePath
是否为空。如果为空,则传递默认图像。确保在传递之前将默认图像转换为
String

首先需要将
R.drawable
转换为
String
,然后将它们分配给
imagePath

示例

spTypePets.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        Resources res = getResources();
        String spinner = spTypePets.getSelectedItem().toString();

        switch (position) {
            case 0:
              imagePath = getURLForResource(R.drawable.dog);
              Glide.with(PetsFormActivity.this).load(R.drawable.dog).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
                break;
                     ......
            }   
      }

public String getURLForResource (int resourceId) {
    return Uri.parse("android.resource://"+R.class.getPackage().getName()+"/" +resourceId).toString();
 }
sptypets.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
Resources res=getResources();
字符串微调器=spTypePets.getSelectedItem().toString();
开关(位置){
案例0:
imagePath=getURLForResource(R.drawable.dog);
Glide.with(PetsFormActivity.this).load(R.drawable.dog).apply(RequestOptions.circleCropTransform()).into(ivPetImageForm);
打破
......
}   
}
公共字符串getURLForResource(int resourceId){
返回Uri.parse(“android.resource://”+R.class.getPackage().getName()+“/”+resourceId.toString();
}

单击
btnSave
时,检查
imagePath
是否为空。如果为空,则传递默认图像。确保在传递之前将默认图像转换为
String

“Hasta aqítodo bien,el problema es que ahora necerto cargar también esa image por defecto al crear un objeto del tipo”Pet“这是一个公式化的过程,这是决定性的:我不知道该怎么做,我不知道该怎么做,因为我不知道该怎么做。”。“请用英语。对不起,我忘了翻译那部分。哈哈哈。所以如果imagePath为空,它应该上传默认图像,否则它应该上传特定的可绘制图像?没错,这是我的想法,但我一直在尝试,我无法存储默认图像以通过集合。“我的问题是,卡加·塔姆比(cargar también esa imagen por defecto al crear un objeto del tipo)“宠物”是一种公式化的交通工具,它的决定是:不可能是一个错误,也不可能是一个错误。“请用英语。对不起,我忘了翻译那部分。哈哈哈。所以如果imagePath为空,它应该上传默认图像,否则它应该上传特定的可绘制图像?没错,这是我的想法,但我一直在尝试,我无法存储默认图像以通过集合。