在我的应用程序中,我有选项卡菜单:添加选项卡,查看选项卡。
在添加选项卡中:我将数据添加到数据库在视图选项卡中:我从数据库中选择数据到列表视图中
现在我有问题:当我从添加选项卡添加数据并切换到视图选项卡时,我无法查看最后一次添加到数据库中,但是如果我关闭应用程序并重新打开它,我可以得到最后一次添加
关于解决这个问题的任何想法请
代码 :
`查看标签代码:
公共类 ViewEvents 扩展 Activity {
DBAdapter DB=new DBAdapter(this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewevents);
final ListView myListView = (ListView)findViewById(R.id.MyList);
// final EditText myEditText = (EditText)findViewById(R.id.myEditText);
// Create the array list of to do items
final ArrayList<String> todoItems = new ArrayList<String>();
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, todoItems);
DB.open();
Cursor c=DB.select();
c.moveToFirst();
Integer n=new Integer(c.getCount());
for(int i=0;i<c.getCount();i++)
{
todoItems.add(0, c.getString(0));
c.moveToNext();
}
// todoItems.add(0, c.getString(0));
aa.notifyDataSetChanged();
myListView.setAdapter(aa);
}
}
添加标签代码:
public View getView(int position, View convertView, ViewGroup parent) {
ButtonHolder holder2;
if (convertView == null) {
holder2 = new ButtonHolder();
convertView = mInflater.inflate(R.layout.item, null);
holder2.caption = (Button) convertView.findViewById(R.id.Bte);
convertView.setTag(holder2);
} else {
holder2 = (ButtonHolder) convertView.getTag();
}
holder2.caption.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
TextView names = holderpartner.caption;
TextView date = holderdv.caption;
TextView time = holderviewmtime.caption;
String address = "sdfgkhj";
event e=new event( names.getText().toString(), address,date.getText().toString(), new java.sql.Time(9, 30, 30));
DB.open();
DB.insertTask(e);
date.setText("");
time.setText("");
Toast.makeText(getBaseContext(), "Done",Toast.LENGTH_LONG).show();
}
});`