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 8413211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:52:29+00:00 2026-06-10T00:52:29+00:00

I have method in my Activity, which should add items from the webservice if

  • 0

I have method in my Activity, which should add items from the webservice if user scrolls down the TableLayout. It looks like:

  private void getOrderList(String page, String perpage) throws JSONException
{

    DatabaseHandler db = new DatabaseHandler(getApplicationContext());
    try {
        DataParsing u = new DataParsing();
        UserFunctions n = new UserFunctions();
        JSONObject k= n.getOrders(page,perpage);

        orders = u.wrapOrders(k);
        Dao<ProcessStatus,Integer> dao = db.getStatusDao();
        Log.i("status",dao.queryForAll().toString());
        QueryBuilder<ProcessStatus,Integer> query = dao.queryBuilder();
        Where where = query.where();
        //query.selectColumns(ProcessStatus.STATUS_TITLE).where().eq(ProcessStatus.STATUS_ID,).toString());
        //PreparedQuery<ProcessStatus, Integer> preparedQuery = ((Object) query).prepareQuery();
        String result = "";
        List<String[]> results = null;
        String res[][] = null;

        try{
            for(Order r : orders)
            {
                 GenericRawResults<String[]> rawResults = dao.queryRaw("select "+ ProcessStatus.STATUS_TITLE +" from process_status where "+ ProcessStatus.STATUS_ID + " = " + r.getProcess_status().getProccessStatusId());
                 results = rawResults.getResults();
                 String[] resultArray = results.get(0); //This will select the first result (the first and maybe only row returned)
                 result = resultArray[0]; //This will select the first field in the result (That should be the ID you need)
                 r.getProcess_status().setProccessStatusTitle(result);
                 Log.i("res",r.toString());
                 forPrint.add(r);
                 Log.i("asd",forPrint.toString());
                 //res = Integer.toString(r.getOrderid());             
             }

        }

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

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

This is my function of appending rows in the table:

 private void appendRows(int start,int end) {
    final TableLayout table = (TableLayout)findViewById(R.id.table);
    for (int i=start; i<end; i++)
    { 

        TableRow row = new TableRow(this); 

        TextView idText = new TextView(this);

        idText.setText(Integer.toString(forPrint.get(i).getOrderid()));

        idText.setPadding(10, 0, 0, 20);
        idText.setTextColor(Color.BLACK);
        row.addView(idText);

        TextView textOne = new TextView(this);
        textOne.setText(forPrint.get(i).getTitle());
        textOne.setSingleLine(false);
        textOne.setPadding(15, 0, 0, 0);
        textOne.setTextColor(Color.BLACK);
        row.addView(textOne);

        TextView textTwo = new TextView(this);
        textTwo.setText(Float.toString(forPrint.get(i).getPrice()));
        textTwo.setPadding(15, 0, 0, 0);
        textTwo.setTextColor(Color.BLACK);
        row.addView(textTwo);

         TextView textThree = new TextView(this);
         textThree.setText(forPrint.get(i).getProcess_status().getProccessStatusTitle());
         textThree.setPadding(15, 0, 0, 0);
         textThree.setTextColor(Color.BLACK);
        row.addView(textThree);

       table.addView(row, new TableLayout.LayoutParams()); 
    }
 }

And, finally, my GestureListener:

  class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener
{

public boolean onDown(MotionEvent arg0) {
    Log.i("asd","sdas");
    return false;
}

public void onLongPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float arg2,
        float arg3) {
    mIsScrolling = true;   

    float pos = e2.getY() - e1.getY();
    if (pos< -120)
    {
        Log.i("sd","I'm here");
        try {

            page+=1;
            start +=10;    // start position of the new items
            end+=10;       // end position of the new items
            Log.i("position down",Integer.toString(page));
            getOrderList(Integer.toString(page),"10");
            appendRows(start,end);

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    return true;
   }
   }

It works good except situation when I scroll to the end of the data…It throws IndexOutOfBoundsException like this:

    08-17 10:46:34.749: E/AndroidRuntime(6321): FATAL EXCEPTION: main
08-17 10:46:34.749: E/AndroidRuntime(6321): java.lang.IndexOutOfBoundsException: Invalid index 58, size is 58
08-17 10:46:34.749: E/AndroidRuntime(6321):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at java.util.ArrayList.get(ArrayList.java:311)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.assignmentexpert.DashboardActivity.appendRows(DashboardActivity.java:192)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.assignmentexpert.DashboardActivity.access$2(DashboardActivity.java:183)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.assignmentexpert.DashboardActivity$MyGestureListener.onScroll(DashboardActivity.java:264)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:541)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.assignmentexpert.DashboardActivity.dispatchTouchEvent(DashboardActivity.java:334)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1734)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2216)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1887)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.os.Looper.loop(Looper.java:123)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at java.lang.reflect.Method.invoke(Method.java:507)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-17 10:46:34.749: E/AndroidRuntime(6321):     at dalvik.system.NativeStart.main(Native Method)

How should I implement this?

  • 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-10T00:52:30+00:00Added an answer on June 10, 2026 at 12:52 am

    I solved this by simple verification. My method appendRows() looks like this:

    private void appendRows(int start,int end) {
        final TableLayout table = (TableLayout)findViewById(R.id.table);
        if(forPrint.size() >= end)  // implementation which solved my problem
        {
            for (int i=start; i<end-1; i++)
            { 
    
                TableRow row = new TableRow(this); 
    
                TextView idText = new TextView(this);
    
                idText.setText(Integer.toString(forPrint.get(i).getOrderid()));
    
                idText.setPadding(10, 0, 0, 20);
                idText.setTextColor(Color.BLACK);
                row.addView(idText);
    
                TextView textOne = new TextView(this);
                textOne.setText(forPrint.get(i).getTitle());
                textOne.setSingleLine(false);
                textOne.setPadding(15, 0, 0, 0);
                textOne.setTextColor(Color.BLACK);
                row.addView(textOne);
    
                TextView textTwo = new TextView(this);
                textTwo.setText(Float.toString(forPrint.get(i).getPrice()));
                textTwo.setPadding(15, 0, 0, 0);
                textTwo.setTextColor(Color.BLACK);
                row.addView(textTwo);
    
                 TextView textThree = new TextView(this);
                 textThree.setText(forPrint.get(i).getProcess_status().getProccessStatusTitle());
                 textThree.setPadding(15, 0, 0, 0);
                 textThree.setTextColor(Color.BLACK);
                row.addView(textThree);
    
               table.addView(row, new TableLayout.LayoutParams()); 
             }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that launches another activity with startActivityForResult method. I would like
I have a method which should return a list of anonymous objects with a
I have a activity which showing the 20 items in listview, at bottom list
I have an activity which displays some data fetched from the server. If no
I would like to finish an activity from inside the onCreate method. When I
In my activity oncreate method, i have called a service using OnStartCommand(). My requirement
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
I have an activity in whose onCreate method an Init function is called (the
I have Activity with ListView inside it and in the onCreate method of the
Long Story Short: a method of my activity updates and scrolls the ListView through

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.