所以问题是我无法通过单击将项目添加到 Sugar orm 数据库中,但我设法将它们添加到列表中。奇怪的是,它向我显示了数据库中已经存在的 5 个空对象。我应该怎么办?
public class FragmentOne extends ListFragment {
private TextView iaDdebt;
private Button btnAdd;
private EditText etAmount;
private List<Debt> values;
String debtTemp;
String temp;
private ArrayAdapter<Debt> adapter;
Debt debt;
List<Debt> loadList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutInflater lf = getActivity().getLayoutInflater();
View rootView = lf.inflate(R.layout.fragment_one, container, false);
iaDdebt = (TextView) rootView.findViewById(R.id.iaDebt);
btnAdd = (Button) rootView.findViewById(R.id.btnAdd);
etAmount = (EditText) rootView.findViewById(R.id.etAmount);
loadList = Debt.listAll(Debt.class);
adapter = new ArrayAdapter<>(getActivity(),
R.layout.my_list_item, R.id.iaDebt, loadList);
setListAdapter(adapter);
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
temp = etAmount.getText().toString();
debt = new Debt(temp);
loadList.add(debt);
adapter.notifyDataSetChanged();
}
});
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}