public class CustomActivity extends AppCompatActivity {
RecyclerView recyview;
QuickAdapter adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);
initView();
setCustomView();
}
private void initView() {
recyview = findViewById(R.id.recyview);
}
private void setCustomView() {
Adx3CustomAdView.getInstance().loadData(getApplicationContext(), "UnitId");
}
}
LinearLayoutManager manager = new LinearLayoutManager(this);
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyview.setLayoutManager(manager);
adapter = new QuickAdapter(getStrings());
recyview.setAdapter(adapter);
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_item"
xmlns:app="http://schemas.android.com/apk/res-auto">
<io.adx3.library.view.Adx3CustomLayoutAdview
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<io.adx3.library.view.Adx3ImageItemView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<io.adx3.library.view.Adx3TextItemView
android:id="@+id/textview"
android:layout_below="@+id/image"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="30dp" />
</io.adx3.library.view.Adx3CustomLayoutAdview>
</androidx.constraintlayout.widget.ConstraintLayout>
public class QuickAdapter extends RecyclerView.Adapter<QuickAdapter.ViewHolder> {
List<String> list;
public QuickAdapter(List<String> strings) {
list = strings;
}
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recyclview, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull QuickAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
holder.view.setData(position, new CustomItemListener() {
@Override
public void loadByUser() {
}
@Override
public void loadUrl(String url) {
}
});
}
@Override
public int getItemCount() {
return list.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
Adx3CustomLayoutAdview view;
Adx3ImageItemView imageItemView;
Adx3TextItemView textItemView;
ConstraintLayout layout_item;
public ViewHolder(@NonNull View itemView) {
super(itemView);
view = itemView.findViewById(R.id.layout);
imageItemView = itemView.findViewById(R.id.image);
textItemView = itemView.findViewById(R.id.textview);
layout_item = itemView.findViewById(R.id.layout_item);
}
}
}