单击适配器类中的国家/地区选择器时,崩溃显示java.lang.ClassCastException: com.sunday.holiday.com.teller.DemoApplication cannot be cast to android.app.Activity
。
这是我的代码:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyView> {
String date1,date;
public static List<previousModel> list;
Context context1;
public static ArrayList<QualificationModel1> list_n= new ArrayList<QualificationModel1>();
public class MyView extends RecyclerView.ViewHolder {
public EditText edt_qual,edt_position,edt_cntry,edt_from_date1,edt_to_date1,edt_experince1,edt_comapny_name;
TextView dumy_to,dummy_frm,curntly,txt_compname;
Switch switchButton;
CountryPicker picker1;
public MyView(View view) {
super(view);//
dummy_frm = (TextView) view.findViewById(R.id.dumy_frm);
txt_compname= (TextView) view.findViewById(R.id.txt_compname);
dumy_to = (TextView) view.findViewById(R.id.dumy_to);
edt_from_date1 = (EditText) view.findViewById(R.id.edt_from_date1);
edt_to_date1 = (EditText) view.findViewById(R.id.edt_to_date1);
curntly= (TextView) view.findViewById(R.id.curntly);
switchButton = (Switch)view. findViewById(R.id.switchButton2);
edt_comapny_name=(EditText)view.findViewById(R.id.edt_comapny_name);
edt_position=(EditText) view.findViewById(R.id.edt_position);
edt_cntry=(EditText) view.findViewById(R.id.edt_cntry);
edt_experince1=(EditText) view.findViewById(R.id.edt_experince1);
switchButton.setChecked(false);
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
if (bChecked) {
curntly.setText("Currently Working");
} else {
curntly.setText("Currently not Working");
}
}
});
edt_from_date1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!((Activity) context1).isFinishing()) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePicker = new DatePickerDialog(context1, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date1 = String.valueOf(dayOfMonth) + "/" + String.valueOf(monthOfYear + 1)
+ "/" + String.valueOf(year);
edt_from_date1.setText(date1);
dummy_frm.setText(date1);
}
}, yy, mm, dd);
datePicker.show();
}
}
});
edt_to_date1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!((Activity) context1).isFinishing()) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePicker = new DatePickerDialog(context1, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date = String.valueOf(dayOfMonth) + "/" + String.valueOf(monthOfYear + 1)
+ "/" + String.valueOf(year);
edt_to_date1.setText(date);
dumy_to.setText(date);
}
}, yy, mm, dd);
datePicker.show();
}
}
});
picker1 = CountryPicker.newInstance("Select Country"); // dialog title
picker1.setListener(new CountryPickerListener() {
@Override
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
edt_cntry.setText(name);
picker1.dismiss();
}
});
edt_cntry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!((Activity) context1).isFinishing()) {
picker1.show(((ForumActivity) context1).getSupportFragmentManager(), "COUNTRY_PICKER");
}
}
});
}
}
public RecyclerViewAdapter(List<previousModel> horizontalList,Context context) {
this.list = horizontalList;
this.context1=context;
}
@Override
public MyView onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.previous_work_layout, parent, false);
return new MyView(itemView);
}
@Override
public void onBindViewHolder(final MyView holder, final int position) {
int k=position+1;
}
}
@Override
public int getItemCount() {
return list.size();
}
}
答案 0 :(得分:0)
您的CountryPicker
未初始化。在设置标题初始化之前如下。
picker1 = new DatePickerDialog(pass context,...);
picker1 = CountryPicker.newInstance("Select Country");