Anhone可以帮助我或为我指明正确的方向吗?从当前表到输出表的最简单方法是什么?
当前表
ID |类型|金额|
2 | A | 19 | | | | | |
2 | B | 6 | | | | | |
3 | A | 5 | | | | | | | | | | |
3 | B | 11 | | | | | |
4 | A | 1的| |
4 | B | 23 | | | | | | |
期望的输出
ID |类型|金额|更改
2 | A | 19 | | | | | | 13 | |
2 | B | 6 | | | | | | | | | | | | -6 -6 | |
3 | A | 5 | | | | | | | | | | | -22
3 | B | 11 | | | | | | |
4 | A | 1的| | |
4 | B | 23 | | | | | | | |
答案 0 :(得分:0)
我不知道如何将值放在行上。例如,对于任何给定的ID,您都可以从“ A”值中减去“ B”值。例如:
public class ColorDialogFragment extends DialogFragment {
private View view;
private TabLayout tabLayout;
private ViewPager viewPager;
private ColorFragmentPagerAdapter colorFragmentPagerAdapter;
public static ColorDialogFragment newInstance() {
ColorDialogFragment colorDialogFragment = new ColorDialogFragment();
return colorDialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// TODO: Read from WeNoteOptions.
final int position = 0;
this.viewPager.setCurrentItem(position);
updateButtonVisibility(position);
}
private View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container) {
View view = inflater.inflate(R.layout.color_dialog_fragment, container, false);
this.tabLayout = view.findViewById(R.id.tab_layout);
this.viewPager = view.findViewById(R.id.view_pager);
this.colorFragmentPagerAdapter = new ColorFragmentPagerAdapter(this.getChildFragmentManager());
this.viewPager.setAdapter(this.colorFragmentPagerAdapter);
this.tabLayout.setupWithViewPager(this.viewPager);
this.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
updateButtonVisibility(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
return view;
}
private void updateButtonVisibility(int position) {
if (position == 1) {
((AlertDialog)getDialog()).getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
} else {
((AlertDialog)getDialog()).getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.INVISIBLE);
}
}
// https://stackoverflow.com/questions/20303865/viewpager-in-dialogfragment-illegalstateexception-fragment-does-not-have-a-vi
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return this.view;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
this.view = onCreateView(layoutInflater, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.select_a_color)
.setView(this.view)
.setPositiveButton(R.string.select_color, (dialogInterface, i) -> {
});
return alertDialogBuilder.create();
}
}