简体   繁体   English

Arraylist整数到android中的可绘制图像

[英]Arraylist Integer to Drawable Images in android

imageList should be arraylist imageList应该是arraylist

and in my bean how i can convert it into Drawable and how can we set it to the parameters in bean 以及在我的bean中如何将其转换为Drawable以及如何将其设置为bean中的参数

below given class is my bean 下面给定的类是我的豆子

public class ParkPhotoFetchBean {
    private int parkPics;
    arraylist should come here

and we need to change it into drawable so how can i set it by changing it to drawableimage 我们需要将其更改为drawable,所以我如何通过将其更改为drawableimage进行设置

    void ParkPhotoFetchBin(int parkPics){
        this.parkPics = parkPics;
    }

    public int getParkPics() {
        return parkPics;
    }
getter and setter
    public void setParkPics(int parkPics) {
        this.parkPics = parkPics;
    }

}

another class is 另一类是

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.project.parkingapplication.adapter.HorizontalRecyclerAdapter;
import com.project.parkingapplication.entities.ParkPhotoFetchBean;

import java.util.ArrayList;
import java.util.List;

public class BookingDetail extends AppCompatActivity {
    private List<ParkPhotoFetchBean> parkingPhotoList = new ArrayList<>();
    RecyclerView rvContainer;
    Activity activity;
    HorizontalRecyclerAdapter myRecyclerViewAdapter;
    com.project.parkingapplication.entities.ParkPhotoFetchBean myRecyclerBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_booking_detail);
        activity = this;
        rvContainer.addItemDecoration(new DividerItemDecoration(BookingDetail.this, LinearLayoutManager.HORIZONTAL));
        myRecyclerViewAdapter = new HorizontalRecyclerAdapter(parkingPhotoList, this);
        LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(BookingDetail.this, LinearLayoutManager.HORIZONTAL, false);
        rvContainer.setLayoutManager(horizontalLayoutManager);
        rvContainer.setAdapter(myRecyclerViewAdapter);
        populatePhotoList();

    }

    private void populatePhotoList() {
        ArrayList<Integer> imagesList = new ArrayList();
        imagesList.add(R.drawable.image1);
        imagesList.add(R.drawable.image2);
        imagesList.add(R.drawable.image3);
        imagesList.add(R.drawable.image4);
        imagesList.add(R.drawable.car);

        ParkPhotoFetchBean parkPhotoFetchBean = new ParkPhotoFetchBean(imagesList); //image List should be array list and in my //bean how i can convert it into drawable

    }

    private void mappingWidget() {
        rvContainer = findViewById(R.id.rv_booking_detail_image_slider);
    }
}

Solution: 解:

Instead of this: 代替这个:

ParkPhotoFetchBean parkPhotoFetchBean = new ParkPhotoFetchBean(imagesList); 

Write: 写:

for(int i=0; i<imagesList.size(); i++) 
{
    parkingPhotoList.add(new ParkPhotoFetchBean(imagesList.get(i)))
}
myRecyclerViewAdapter.notifyDataSetChanged()

Now, you can use parkingPhotoList in your activity which contains your images from the bean class. 现在,您可以在活动中使用parkingPhotoList ,其中包含来自bean类的图像。 You don't have to pass your arraylist to your bean class. 您不必将arraylist传递给bean类。 You images will be displayed in RecyclerView 您的图像将显示在RecyclerView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM