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

  • Home
  • SEARCH
  • 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 6164299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:58:13+00:00 2026-05-23T21:58:13+00:00

I would like to refresh the ListView every time I change the base data.

  • 0

I would like to refresh the ListView every time I change the base data. Please see the following
example:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mListUsers = getUsers();
lvList = (ListView) findViewById(R.id.event_list);
lvList.setAdapter(new ListAdapter(mContext, R.id.event_list, mListUsers));

    btn_next=(Button)findViewById(R.id.btn_next);
btn_next.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
 SimpleDateFormat postFormater = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH); 
 String newDateStr = lbl_date.getText().toString();         
 Calendar c = Calendar.getInstance();
 try {
 c.setTime(postFormater.parse(newDateStr));
 } catch (ParseException e) {
// TODO Auto-generated catch block
 e.printStackTrace();
}
c.add(Calendar.DATE, 1);  // number of days to add
newDateStr = postFormater.format(c.getTime());
lbl_date.setText(newDateStr.toString());

mListUsers = getUsers();
lvList = (ListView) findViewById(R.id.event_list);
lvList.setAdapter(new ListAdapter(mContext, R.id.event_list, mListUsers));
}
});

}

public ArrayList<main_list_item> getUsers(){                
DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(this);
try {
            dbAdapter.createDataBase();
        } catch (IOException e) {
            Log.i("*** select ",e.getMessage());
        }
        dbAdapter.openDataBase();

        SimpleDateFormat curFormater1 = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = curFormater1.format(new Date(lbl_date.getText().toString()));
        String query;       
        if(all==1){
            query="SELECT id,dateS, dateE, (select eventname from tbEvent_name where tbEvent_name.id=eventId)as event FROM tbTransaction";
        }
        else{
            query="SELECT id,dateS, dateE, (select eventname from tbEvent_name where tbEvent_name.id=eventId)as event FROM tbTransaction WHERE SUBSTR(sDate,1,10)='"+dateString+"'";
        }

        ArrayList<ArrayList<String>> stringList = dbAdapter.selectRecordsFromDBList(query, null);
        dbAdapter.close();

        SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH);
        Date dateObj = null;

        ArrayList<main_list_item> usersList = new ArrayList<main_list_item>();
        for (int i = 0; i < stringList.size(); i++) {
            ArrayList<String> list = stringList.get(i);
            main_list_item user = new main_list_item();
            try {
                user.id=Integer.parseInt(list.get(0));
                user.event= list.get(3);

        String newDateStr1 = postFormater1.format(dateObj);

                user.dateS=list.get(1);
                user.dateE=list.get(2);

            } catch (Exception e) {
                e.printStackTrace();
            }
            usersList.add(user);
        }
        return usersList;
    }

 // ***ListAdapter***
    private class ListAdapter extends ArrayAdapter<main_list_item> {  // --CloneChangeRequired
        private ArrayList<main_list_item> mList;  // --CloneChangeRequired
        private Context mContext;

        public ListAdapter(Context context, int textViewResourceId,ArrayList<main_list_item> list) { // --CloneChangeRequired
            super(context, textViewResourceId, list);
            this.mList = list;
            this.mContext = context;
        }

        public View getView(int position, View convertView, ViewGroup parent){
            View view = convertView;
            try{
            if (view == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.main_list_item, null);   // --CloneChangeRequired(list_item)
            }
            final main_list_item listItem = mList.get(position);    // --CloneChangeRequired                
            if (listItem != null) {
                // setting list_item views                      
                ((TextView) view.findViewById(R.id.lbl_id) ).setText( listItem.getId()+"");

                ((TextView) view.findViewById(R.id.lbl_event) ).setText( listItem.getEvent()+"");
                ((TextView) view.findViewById(R.id.lbl_sdate) ).setText( listItem.getsDate()+"");
                ((TextView) view.findViewById(R.id.lbl_edate) ).setText( listItem.geteDate()+"");

            }}catch(Exception e){
                e.printStackTrace();
            }

            return view;
        }       
    }

Its is correct way?

In this code I want to refresh listview when ‘btn_next’ click.

And also I want to separate two parts,put heading.

please give me guide..

thanks in advance

Uncaught handler: thread main exiting due to uncaught exception
java.lang.NullPointerException
at com.apt.eTrack.ETrackActivity$4.onClick(ETrackActivity.java:153)
at android.view.View.performClick(View.java:2344)
at android.view.View.onTouchEvent(View.java:4133)
at android.widget.TextView.onTouchEvent(TextView.java:6510)
at android.view.View.dispatchTouchEvent(View.java:3672)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
at    com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  • 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-05-23T21:58:14+00:00Added an answer on May 23, 2026 at 9:58 pm
    static ListAdapter mListAdapter;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mListUsers = getUsers();
        mListAdapter=new ListAdapter(mContext, R.id.event_list, mListUsers);
        lvList = (ListView) findViewById(R.id.event_list);
        lvList.setAdapter(mListAdapter);
    
        btn_next=(Button)findViewById(R.id.btn_next);
        btn_next.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                SimpleDateFormat postFormater = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH); 
                String newDateStr = lbl_date.getText().toString();         
                Calendar c = Calendar.getInstance();
                try {
                    c.setTime(postFormater.parse(newDateStr));
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                c.add(Calendar.DATE, 1);  // number of days to add
                newDateStr = postFormater.format(c.getTime());
                lbl_date.setText(newDateStr.toString());
    
                mListUsers = getUsers();
                mListAdapter.notifyDataSetChanged();
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to load/refresh a particular page for every 10 secs to view
I have an iframe which I would like to refresh every fifteen seconds, but
I have a page where I would like it to remain static after refresh
I am working on a website, and I would like to refresh a portion
I have a ListView which uses a CursorAdatper as its adapter. I would like
I would like to implement a Pull down to refresh into my application. Just
I would like to have the History.back(); functionality with a complete refresh of previous
I'm writing a game server in C# and would like to reload or refresh
I would like to refresh a view when I open the app. When I'm
I would like to use jQuery to refresh a partial on a page, but

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.