Multiple

Multiple advertisements are suitable for interspersing advertisement content in the system ListView or RecyclerView list, keeping the style and layout consistent with the user, and perfectly integrating the advertisement type into the list layout.

Before you begin

You should finish the step of the Guide first.

This guide uses RecyclerView as a display example, and the related display process of ListView is the same.

Control initialization

First of all, based on the principle of multiple advertisement displays, before the list data is filled, the control initialization needs to be completed. The example is as follows:

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");
    }

}

List adapter added

After the initialization of the ad control is completed, according to the example, the user completes the initialization and data filling of the list control. The example is as follows:

LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyview.setLayoutManager(manager);

        adapter = new QuickAdapter(getStrings());
        recyview.setAdapter(adapter);

According to the current example of RecyclerView mode, it is displayed as a horizontal queue and QuickAdapter is the default data adapter of RecyclerView. Users are requested to make their own adjustments according to their own business needs.

Layout

The current layout is configured as a list layout and a single-item layout. According to the actual requirements of the business, the layout style and layout may be different. The reference example is as follows:

<?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>

The current layout adopts the form of picture + text for page display.

Data adapter

After completing the layout and control initialization, for the list control, the following example shows the adapter filling and control-related event operations.

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);
        }
    }
}
  • laodByUser - Parameter callback method, the current callback method is used to fill the user's own data, the user can configure the content of the non-advertising space, the current configuration is the content of the page text box.

  • loadUrl - Click the callback method, the current callback method can distinguish the user's own control or advertising space, the user can complete his own operation logic according to the current callback, and the operation of the advertising space does not affect the user's business process.

So far, the process of multiple advertisements has been added; the user list display logic has been isolated from multiple advertisements; and the user-defined process will not be affected by the display and configuration of advertisements.

Last updated