imageList应该是arraylist
以及在我的bean中如何将其转换为Drawable和 我们如何将其设置为bean中的参数
在给定的类下面是我的豆子
public class ParkPhotoFetchBean {
private int parkPics;
arraylist should come here
,我们需要将其更改为可绘制的 如何通过将其更改为drawableimage来设置
void ParkPhotoFetchBin(int parkPics){
this.parkPics = parkPics;
}
public int getParkPics() {
return parkPics;
}
getter and setter
public void setParkPics(int parkPics) {
this.parkPics = parkPics;
}
}
另一堂课是
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);
}
}
答案 0 :(得分:0)
解决方案:
代替此:
ParkPhotoFetchBean parkPhotoFetchBean = new ParkPhotoFetchBean(imagesList);
写:
for(int i=0; i<imagesList.size(); i++)
{
parkingPhotoList.add(new ParkPhotoFetchBean(imagesList.get(i)))
}
myRecyclerViewAdapter.notifyDataSetChanged()
现在,您可以在包含来自Bean类的图像的活动中使用parkingPhotoList
。您不必将arraylist传递给bean类。您的图片将显示在RecyclerView