将参数传递给android的自定义视图

我正在尝试向我的应用添加日历。我用它自定义视图 我想将事件从数据库添加到日历中。我需要将字符串传递到自定义视图,以便它将知道从何处检索数据。我没找到怎么做。

package com.example.homerunner;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class CoachCalendarActivity extends AppCompatActivity {

    CustomCalendarView customCalendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coach_calendar);

        Intent intent = getIntent();
        String uid = intent.getStringExtra("uid");
        Log.d("Loge", "onCreate: " + uid);

        customCalendarView = (CustomCalendarView)findViewById(R.id.custom_calender_view);
    }
}

the string that I want to pass is saved in String uid = intent.getStringExtra("uid");

自定义查看代码



public class CustomCalendarView extends LinearLayout implements View.OnClickListener, AdapterView.OnItemClickListener, EventRecyclerAdapter.OnEventListener {

    Context context;

    public CustomCalendarView(Context context) {
        super(context);
    }

    public CustomCalendarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

    }

    public CustomCalendarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
评论