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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:00:24+00:00 2026-06-15T04:00:24+00:00

I’m doing a app can update data every 1 minutes, data will from database

  • 0

I’m doing a app can update data every 1 minutes, data will from database mysql on server to show on listview of my app android. My problem is when show data the first is ok but when show data the second on listview, data of the first and the second is duplication.Can you help me!
Source code:

public class Hoadon extends Activity {
JSONArray jArray;
String result = null;
InputStream is = null;
StringBuilder sb = null;
ArrayList<String> al = new ArrayList<String>();
ArrayList<String> al1 = new ArrayList<String>();
ArrayList<String> al2 = new ArrayList<String>();
ArrayList<String> al3 = new ArrayList<String>();
ArrayList<String> al1a = new ArrayList<String>();
String date;
String name;
String address;
String url;
String code;
int responseCode;
private String IDinvoice;
private TimerTask mTimerTask;
private Timer t=new Timer();
private final Handler handler=new Handler();
private ListView listview;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hoadon);
    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }
    else {
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }
    try {
        URL url = new URL("http://longvansolution.tk/monthlytarget.php");
        URLConnection connection = url.openConnection();
        connection.setConnectTimeout(2000);
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        responseCode = httpConnection.getResponseCode();
    } catch (Exception e) {
    }
    try {
        if (isNetworkAvailable() == true
                //&& responseCode == HttpURLConnection.HTTP_OK
                ) {
            //new LoadData().execute();
            al.clear();
            al1.clear();
            al2.clear();
            al3.clear();
            al1a.clear();

            doTimerTask();
        } else {
            AlertDialog.Builder ad = new AlertDialog.Builder(this);
            ad.setMessage("No Internet Connection available!!!");
            ad.show();
        }
    } catch (Exception e) {

    }
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        IDinvoice = extras.getString("IDinvoice");
    }


}

public void doTimerTask(){
    mTimerTask = new TimerTask() {       
            public void run() {
                    handler.post(new Runnable() {
                            public void run() {
                                new LoadData().execute();
                                Log.d("TIMER", "TimerTask run");
                            }
                   });
            }};
        // public void schedule (TimerTask task, long delay, long period) 
        t.schedule(mTimerTask, 500, 10000);  // 
     }
@Override
public void onBackPressed() {

    //do something with bitmap
}
private class LoadData extends AsyncTask<Void, Void, Void> {
    private ProgressDialog progressDialog;


    @Override
    // can use UI thread here
    protected void onPreExecute() {
        this.progressDialog = ProgressDialog.show(
                Hoadon.this, "", " Loading...");
    }

    @Override
    protected void onPostExecute(final Void unused) {
        this.progressDialog.dismiss();
        try {
            listview = (ListView) findViewById(R.id.listView1);
            this.progressDialog.dismiss();
            listview.setAdapter(new DataAdapter(Hoadon.this,
                    al.toArray(new String[al.size()]), al1a
                            .toArray(new String[al1a.size()]), al1
                            .toArray(new String[al1.size()]), al2
                            .toArray(new String[al2.size()])));
            listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    String t = al3.get(position);
                    Intent i = new Intent(Hoadon.this,
                            Signature.class);
                    i.putExtra("url", t);
                    startActivity(i);
                }
            });
        } catch (Exception e) {

            Toast.makeText(getApplicationContext(), e.toString(),
                    Toast.LENGTH_LONG).show();
        }

    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        // HTTP post

        try {

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            HttpClient httpclient = new DefaultHttpClient();
            try {
                HttpPost httppost = new HttpPost(
                        "http://longvansolution.tk/monthlytarget.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.toString(),
                        Toast.LENGTH_LONG).show();
            }
            // buffered reader
            try {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is, "iso-8859-1"), 80);
                sb = new StringBuilder();
                sb.append(reader.readLine() + "\n");
                String line = "0";
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.toString(),
                        Toast.LENGTH_LONG).show();
            }
            try {
                jArray = new JSONArray(result);
                JSONObject json_data = null;
                for (int i = 0; i < jArray.length(); i++) {
                    json_data = jArray.getJSONObject(i);
                    date = json_data.getString("date");
                    address = json_data.getString("address");
                    name = json_data.getString("name");
                    url = json_data.getString("url");
                    code = json_data.getString("code");
                    al.add(date);
                    al1a.add(code);
                    al1.add(name);
                    al2.add(address);
                    al3.add(url);
                }
            } catch (JSONException e) {
                Toast.makeText(getApplicationContext(), e.toString(),
                        Toast.LENGTH_LONG).show();
            }
        } catch (ParseException e) {
            // Log.e("log_tag", "Error in http connection" + e.toString());
            Toast.makeText(getApplicationContext(), e.toString(),
                    Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            // Log.e("log_tag", "Error in http connection" + e.toString());
            Toast.makeText(getApplicationContext(), e.toString(),
                    Toast.LENGTH_LONG).show();
        }

        return null;

    }
}

public boolean isNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // if no network is available networkInfo will be null, otherwise check
    // if we are connected
    if (networkInfo != null && networkInfo.isConnected()) {

        // Log.i("net status:", "Online...!!!");
        return true;
    }
    // Log.i("net status:", "offline...!!!");
    return false;
}

}

Source DataAdapter

public class DataAdapter extends BaseAdapter {
Context mContext;
private LayoutInflater mInflater;
String[] date;
String[] code;
String[] address;
String[] name;

public DataAdapter(Context c, String[] date,String[] code, String[] name, String[] address) {
    this.date = date;
    this.code=code;
    this.name = name;
    this.address = address;
    mContext = c;
    mInflater = LayoutInflater.from(c);
}

public void clearData() {
    // clear the data
    Arrays.fill(date, null);
    Arrays.fill(code, null);
    Arrays.fill(address, null);
    Arrays.fill(name, null);
}

public int getCount() {
    return date.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.customgrid, parent, false);
        holder = new ViewHolder();
        holder.date = (TextView) convertView.findViewById(R.id.date);
        holder.code=(TextView)convertView.findViewById(R.id.mahd);
        holder.name = (TextView) convertView.findViewById(R.id.name);
        holder.address = (TextView) convertView.findViewById(R.id.address);
        if (position == 0) {
            convertView.setTag(holder);
        }
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    try {

        holder.date.setText(date[position]);
        holder.code.setText(code[position]);
        holder.name.setText(name[position]);
        holder.address.setText(address[position]);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return convertView;
}

static class ViewHolder {
    TextView date,code;
    TextView name, address;
}

}

  • 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-15T04:00:25+00:00Added an answer on June 15, 2026 at 4:00 am

    you should clear your arralist every LoadData task.

    try {
     jArray = new JSONArray(result);
     JSONObject json_data = null;
    
     al.clear();
     al1.clear();
     al2.clear();
     al3.clear();
     al1a.clear();
    
     for (int i = 0; i < jArray.length(); i++) {
                    json_data = jArray.getJSONObject(i);
                    date = json_data.getString("date");
                    address = json_data.getString("address");
                    name = json_data.getString("name");
                    url = json_data.getString("url");
                    code = json_data.getString("code");
                    al.add(date);
                    al1a.add(code);
                    al1.add(name);
                    al2.add(address);
                    al3.add(url);
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.