我使用ListActivity
在Android中制作了以下程序:
package com.infy.dataloaderdemo;
import java.util.ArrayList;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Browser;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class DataLoaderOfDataBase extends ListActivity {
/** Called when the activity is first created. */
ListView listView;
ArrayList<String> arrayList=new ArrayList<String>();
Cursor mCursor;
Button mButton;
EditText e;
public static final String KEY_ROWID = "_id";
public static final String KEY_ISBN = "isbn";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dataloaderlist);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mButton=(Button)findViewById(R.id.push);
mButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pushDataInList();
}
});
}
public void pushDataInList(){
String[] displayFields = new String[] {KEY_ROWID,KEY_ISBN};
int[] displayViews = new int[] { android.R.id.text1,android.R.id.text2 };
// Cursor cur = managedQuery(android.provider.Browser.BOOKMARKS_URI,projection, null, null, null);
DBAdapter dbAdapter=new DBAdapter(this);
long l=dbAdapter.insertTitle("new");
Log.e("l", ""+l);
Cursor cur=null;
//cur=dbAdapter.getTitle(2);
cur = dbAdapter.getAllTitles();
int i=cur.getCount();
Log.e("c", ""+i);
setListAdapter(new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cur,displayFields,displayViews));
}
}
每当我添加数据时,整个列表都会刷新。是否有任何方式在List中添加数据而不刷新它?