gpt4 book ai didi

java - 传递值

转载 作者:行者123 更新时间:2023-12-01 23:26:10 25 4
gpt4 key购买 nike

所以我有一个应用程序,我需要为过滤器选择日期,并且选择工作正常,但我似乎无法更改选择屏幕上的值。这就是我调用 SelectDateFragment 的地方。还有更多代码,但这对此并不重要。

public class filter extends BottomSheetDialogFragment {

public static filter getInstance() {
return new filter();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.filter_popup, container, false);
final TextView dateTextView = (TextView) view.findViewById(R.id.KuupaevValikView);
final View button1 = view.findViewById(R.id.Nooleke1);
final View button2 = view.findViewById(R.id.KuupaevValikView);
final View button3 = view.findViewById(R.id.Nooleke3);
final View button4 = view.findViewById(R.id.Nooleke4);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup1 = new PopupMenu(getActivity(), button1);
//Inflating the Popup using xml file
popup1.getMenuInflater()
.inflate(R.menu.filtermenuprice, popup1.getMenu());

//registering popup1 with OnMenuItemClickListener
popup1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
((TextView)view.findViewById(R.id.HinnavahemikValikView)).setText (item.getTitle());
Toast.makeText(
getActivity(),
"You Clicked : " + item.getTitle(),
Toast.LENGTH_SHORT
).show();
return true;
}
});
popup1.show();
}}
);

button2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
DialogFragment newFragment = new SelectDateFragment();
newFragment.show(getFragmentManager(), "DatePicker");

}
});

这就是它的名称:

public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
return new DatePickerDialog(getActivity(), this, yy, mm, dd);
}

public void onDateSet(DatePicker view, int yy, int mm, int dd) {
populateSetDate(yy, mm+1, dd);
}
public void populateSetDate(int year, int month, int day) {
String date = month+"/"+day+"/"+year;
Toast.makeText(getActivity(), date, Toast.LENGTH_SHORT).show();
//.setText(month+"/"+day+"/"+year);
}

}

我想用名为 date 的字符串替换 button2,但我无法做到这一点。

最佳答案

这应该有效。如果没有,请告诉我,我们将深入研究它:

public void populateSetDate(int year, int month, int day) {
String date = month+"/"+day+"/"+year;
Toast.makeText(getActivity(), date, ).show();
button2.text = date;

}

只要您的 onDateSet 函数正常工作,并且您在 populateSetDate 中获取 Toast,您应该能够使用日期字符串来填充您的 textView(并且您应该稍后更改该变量名称)。

关于java - 传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58307032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com