所以问题是我无法在点击时将项目添加到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);
}
}
答案 0 :(得分:1)
您正在创建一个对象,但实际上并未将新记录保存到数据库。添加保存:
path_to_python\python py-mysql2pgsql (on my machine C:\Python27\python)