开发者

How to insert data in List without refreshing it

I have made the following program in Android using ListActivity:

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) {
          开发者_如何学Go      // 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));


    }

}

Whenever I add a data, the whole list gets refreshed. Is there any way data gets added in List without refreshing it?


Call setNotifyOnChange with false to stop automatic notifications before you start adding data to the list. Once complete, call it again with true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜