Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:23:40+00:00 2026-06-11T22:23:40+00:00

I’ve an app that displays a list of transactions. When i click a button

  • 0

I’ve an app that displays a list of transactions. When i click a button to get the next day’s transactions the listview still has the previous day’s transactions appended to it. How can i clear the array or the adapter before the getView repopulates it?

I’ve tried clear() and adapter.notifyDataSetChanged() but it still doesn’t work.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);

         setCurrentDateOnView();


        Log.e(TAG, "title = " + getTitle());
        Log.e(TAG, "super.title = " + super.getTitle());
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        date = nfcscannerapplication.getDate();
        listView = (ListView) findViewById(R.id.rotalist);
        intent = this.getIntent();
        Bundle bundle = intent.getBundleExtra("rotaArrayBundle");
        if(array != null){
            array.clear();
        }
        array = (ArrayList<?>) bundle.get("rotaArray");

        arrayAdapter = new MySimpleArrayAdapter(this, array);
        arrayAdapter.notifyDataSetChanged();

        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);

.[update]

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);

         setCurrentDateOnView();


        Log.e(TAG, "title = " + getTitle());
        Log.e(TAG, "super.title = " + super.getTitle());
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        date = nfcscannerapplication.getDate();
        listView = (ListView) findViewById(R.id.rotalist);
        intent = this.getIntent();
        Bundle bundle = intent.getBundleExtra("rotaArrayBundle");

        array = (ArrayList<?>) bundle.get("rotaArray");

        if (arrayAdapter == null){

        arrayAdapter = new MySimpleArrayAdapter(this, array);
        }else{

            ((MySimpleArrayAdapter)getListAdapter()).clear();

        }

        for(YourListItem item : yourNewDataArray){
            ((MySimpleArrayAdapter)getListAdapter()).add(item);
        }



        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);


    }// end of onCreate

    private MySimpleArrayAdapter getListAdapter() {
        // TODO Auto-generated method stub
        return arrayAdapter;
    }

.
[update2]

public class GetRota extends NfcBaseActivity implements OnItemClickListener {

    private static final String TAG = GetRota.class.getSimpleName();
    ListView listView;
    Intent intent;
    String callID;
    DateTime date;
    NfcScannerApplication nfcscannerapplication;
    ArrayList<?> array;
    String needName = "";
    MySimpleArrayAdapter arrayAdapter;
    private DatePicker dpResult;
    private int year;
    private int month;
    private int day;

    static final int DATE_DIALOG_ID = 999;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);

         setCurrentDateOnView();


        Log.e(TAG, "title = " + getTitle());
        Log.e(TAG, "super.title = " + super.getTitle());
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        date = nfcscannerapplication.getDate();
        listView = (ListView) findViewById(R.id.rotalist);
        intent = this.getIntent();
        Bundle bundle = intent.getBundleExtra("rotaArrayBundle");

        array = (ArrayList<?>) bundle.get("rotaArray");

        if (arrayAdapter == null){

        arrayAdapter = new MySimpleArrayAdapter(this, array);
        }else{

            ((MySimpleArrayAdapter)getListAdapter()).clear();

        }

//      for(YourListItem item : yourNewDataArray){
//          ((MySimpleArrayAdapter)getListAdapter()).add(item);
//      }



        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);


    }// end of onCreate

    private MySimpleArrayAdapter getListAdapter() {

        return arrayAdapter;
    }

    public void setCurrentDateOnView() {

        dpResult = (DatePicker) findViewById(R.id.datepicker1);

        final Calendar c = Calendar.getInstance();
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        day = c.get(Calendar.DAY_OF_MONTH);


    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menurotadetails, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.previous:
            DateTime now2 = nfcscannerapplication.getDate();
            Log.e(TAG, "now2 = " + now2);
            DateTime dateTimePlusOne2 = now2.minusDays(1);
            Log.e(TAG, "now2 after -1 = " + dateTimePlusOne2);
            nfcscannerapplication.setDate(dateTimePlusOne2);
            DateTimeFormatter fmt2 = DateTimeFormat.forPattern("d-MMM-Y");
            String nextDay2 = fmt2.print(dateTimePlusOne2);

            Intent i2 = new Intent(this, NfcscannerActivity.class);
            i2.putExtra("nextRota", nextDay2);
            i2.setAction("NEXT_ROTA");
            startActivity(i2);
            return true;

        case R.id.next:

            DateTime now = nfcscannerapplication.getDate();
            Log.e(TAG, "now = " + now);
            DateTime dateTimePlusOne = now.plusDays(1);
            Log.e(TAG, "now after +1 = " + dateTimePlusOne);
            nfcscannerapplication.setDate(dateTimePlusOne);
            DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
            String nextDay = fmt.print(dateTimePlusOne);

            Intent i = new Intent(this, NfcscannerActivity.class);
            i.putExtra("nextRota", nextDay);
            i.setAction("NEXT_ROTA");
            startActivity(i);
            return true;

        case R.id.today:
            setCurrentDateOnView();
            showDialog(DATE_DIALOG_ID);
            return true;

        default:

            return super.onOptionsItemSelected(item);
        }
    }






    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            // set date picker as current date
            return new DatePickerDialog(this, datePickerListener, year, month,
                    day);
        }
        return null;
    }

    private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

        // when dialog box is closed, below method will be called.
        public void onDateSet(DatePicker view, int selectedYear,
                int selectedMonth, int selectedDay) {
            year = selectedYear;
            month = selectedMonth;
            day = selectedDay;



            DateTime spinnyTime = new DateTime(year, month+1, day, 1, 1);
            Log.e(TAG, "spinnyTime = " + spinnyTime);
            DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
            String formattedSpinnyTime = fmt.print(spinnyTime);
            Log.e(TAG, "spinnyTime = " + formattedSpinnyTime);
            Log.e(TAG, "year = " + year);
            Log.e(TAG, "month = " + month);
            Log.e(TAG, "day = " + day);


            Intent i = new Intent(GetRota.this, NfcscannerActivity.class);
            i.putExtra("nextRota", formattedSpinnyTime);
            i.setAction("NEXT_ROTA"); 
            startActivity(i);

        }
    };








    private class MySimpleArrayAdapter extends ArrayAdapter<String> {
        private final Context context;
        private final ArrayList<?> list;

        public MySimpleArrayAdapter(Context context, ArrayList<?> list) {

            super(context, R.layout.rotarowlayout);
            Log.e(TAG, "inside adapter constructor");
            this.context = context;
            this.list = list;

            if(list.get(6).toString().equalsIgnoreCase("Out of range")){

                AlertDialog alertDialog = new AlertDialog.Builder(GetRota.this).create();
                alertDialog.setTitle("No Rota Available Error");
                alertDialog.setMessage("Unable To View Rota For That Day");
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {



                    } }); 

                alertDialog.show();
            }
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {


            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View rowView = inflater.inflate(R.layout.rotarowlayout, parent,
                    false);

            TextView startTime = (TextView) rowView
                    .findViewById(R.id.rowstarttime);
            TextView duration = (TextView) rowView
                    .findViewById(R.id.rowduration);
            TextView status = (TextView) rowView.findViewById(R.id.rowstatus);
            TextView name = (TextView) rowView.findViewById(R.id.rowclientname);

            String record = list.get(position).toString();
            String[] itemsInRecord = record.split(",");
            Log.e(TAG, "itemin record = " + itemsInRecord.length);
            String[] recordItem = new String[itemsInRecord.length];

            for (int x = 0; x < itemsInRecord.length; x++) {

                recordItem[x] = itemsInRecord[x];
                Log.e(TAG, "x = " + x);
            }

            startTime.setText("Start Time: " + recordItem[0]);
            duration.setText("Duration:" + recordItem[1]);
            status.setText("Status:" + recordItem[2]);
            name.setText("Client:" + recordItem[3] + recordItem[4]);
            callID = recordItem[5];
            needName = recordItem[6];

            return rowView;

        }

        @Override
        public int getCount() {
            return this.list.size();
        }

    }// end of adapter class

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        Log.e(TAG, "inside onItemClick");

        Intent intent = new Intent(GetRota.this, GetRotaDetails.class);
        intent.putExtra("callIDExtra", callID);

        startActivity(intent);

    }

}// end of GetRota

.

[update3]

@Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);

        // Get your ArrayList from getIntent.getExtras() here, and use my code from above
        Bundle bundle = intent.getBundleExtra("rotaArrayBundle");
        array = (ArrayList<?>) bundle.get("rotaArray");
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);

         setCurrentDateOnView();


        Log.e(TAG, "title = " + getTitle());
        Log.e(TAG, "super.title = " + super.getTitle());
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        date = nfcscannerapplication.getDate();
        listView = (ListView) findViewById(R.id.rotalist);
        onNewIntent(intent);
        //intent = this.getIntent();
        //Bundle bundle = intent.getBundleExtra("rotaArrayBundle");

        //array = (ArrayList<?>) bundle.get("rotaArray");

        if (arrayAdapter == null){

        arrayAdapter = new MySimpleArrayAdapter(this, array);
        }else{

            ((MySimpleArrayAdapter)getListAdapter()).clear();

        }

//      for(YourListItem item : yourNewDataArray){
//          ((MySimpleArrayAdapter)getListAdapter()).add(item);
//      }



        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);


    }// end of onCreate
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:23:41+00:00Added an answer on June 11, 2026 at 10:23 pm

    You should keep the old adapter, and whenever you want to update the list you can do the following:

    ((MySimpleArrayAdapter)getListAdapter()).clear();
    for(String[] item : array){
        ((MySimpleArrayAdapter)getListAdapter()).add(item);
    }
    

    You don’t have to call notifyDataSetChange() either, since clear() and add() does it for you.

    EDIT: Set android:launchMode="singleTop" in the manifest XML on your activity, then override the onNewIntent() method like this:

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);
    }
    

    EDIT2:

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);
    }
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.getrotalayout);
    
         setCurrentDateOnView();
    
    
        Log.e(TAG, "title = " + getTitle());
        Log.e(TAG, "super.title = " + super.getTitle());
        nfcscannerapplication = (NfcScannerApplication) getApplication();
        date = nfcscannerapplication.getDate();
        listView = (ListView) findViewById(R.id.rotalist);
    
    
        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(this);
    
    
    }
    
    @Override
    protected void onResume(){
        super.onResume();
        ArrayList<String[]> array = (ArrayList<String[]>)getIntent().getBundleExtra("rotaArrayBundle").get("rotaArray"); 
        MySimpleArrayAdapter arrayAdapter = new MySimpleArrayAdapter(this, array);
        listView.setAdapter(arrayAdapter)
    }
    

    .

    [update 4]

        for(int i = 0; i < count; i++){
    
                    String s = new Integer(i).toString();
    
                     JSONObject jsonobject2 = (JSONObject) jsonObject1.get(s);
                     String startdate = jsonobject2.getString("StartDate");
                     String duration = jsonobject2.getString("Duration");
                     String callStatusName = jsonobject2.getString("CallStatusName");
                     String clientForeName = jsonobject2.getString("ClientForename");
                     String clientSurName = jsonobject2.getString("ClientSurname");
                     String clientCallId = jsonobject2.getString("CallID");
                     String needName = jsonobject2.getString("NeedName");
    
                     ArrayList<String> arr = new ArrayList<String>();
                     arr.add(startdate);
                     arr.add(duration);
                     arr.add(callStatusName);
                     arr.add(clientForeName);
                     arr.add(clientSurName);
                     arr.add(clientCallId);
                     arr.add(needName);
    
                     Log.e(TAG, "arr size = "+arr.size());
                    arrayList.add(i, arr);
    
                    }
    
                } catch (Exception e) {
    
                    e.printStackTrace();
                }
                return arrayList;
    
    
    class TwoDimentionalArrayList<T> extends ArrayList<ArrayList<T>> {
    
            private static final long serialVersionUID = 1L;
    
            public void addToInnerArray(int index, T element) {
                while (index >= this.size()) {
                    this.add(new ArrayList<T>());
                }
                this.get(index).add(element);
            }
    
            public void addToInnerArray(int index, int index2, T element) {
                while (index >= this.size()) {
                    this.add(new ArrayList<T>());
                }
    
                ArrayList<T> inner = this.get(index);
                while (index2 >= inner.size()) {
                    inner.add(null);
                }
    
                inner.set(index2, element);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.