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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:34:34+00:00 2026-05-27T17:34:34+00:00

I have 1 activity that receives a json object from the server (database) and

  • 0

I have 1 activity that receives a json object from the server (database) and every activity called view (TableLayout but in ScrollView) automatically updates. But when I delete the data in the database (from current activity or directly from the database), the layout won’t update.

I have tried to use the removeView method, call setContentView ‘again’ and re-initialize the layout, and at last I used startActivity and finish methods. But I think that will be weird if used it with something like setInterval method (but on Android) every 10 second.

Anyone know how to refresh view or activity without user noticing that the view has been refresh?

Thank you for reply and sorry if I was wrong. Just let me know the mistake that I made. I search for 1 full day on Google but didn’t find a solution.

I am using Android 2.2 on testing and Linux OS emulator and here is my code:

package com.player;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import com.maestro.Mylist.SideMenuClick;
import com.maestro.libs.Functions;
import com.maestro.libs.SQLiteDatabaseConnector;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class Playlist extends Activity {
private int page = 0;
private TableLayout tblContainer;
private int totalPage;

private String selectedItemIndex;
private TableRow selectedItem;
private Drawable rowColor;

// info to request page
private String roomName;
private String serverAddress;
private String playerUsername;
private String layoutUsername;

private Bundle stateTmp;

/**
 * 
 */
public Playlist() {
    // TODO Auto-generated constructor stub
}


public void getSong(){
    this.tblContainer = new TableLayout(this);

    StringBuilder builder = new StringBuilder();
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(this.serverAddress + "/index.php?m=playlist&a=list&room=" + this.roomName + 
            "&p=" + page + "&ax=ok");
    Functions.showAlert(this, this.serverAddress + "/index.php?m=playlist&a=list&room=" + this.roomName + 
            "&p=" + page + "&ax=ok");

    try{
        HttpResponse response = httpClient.execute(httpGet);
        // httpClient.notify();
        HttpEntity ht = response.getEntity();
        InputStream content = ht.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;

        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }

        try {
            JSONArray obj = new JSONArray(builder.toString());

            for(int i=1, j=0; i<obj.length(); i++, j++){
                TableRow tr = new TableRow(this);
                tr.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        // Functions.showAlert(getRef(), arg0.getTag().toString());
                        selectedItem = (TableRow) arg0;
                        rowColor = arg0.getBackground();
                        arg0.setBackgroundColor(0xFFFFA500);

                        selectedItemIndex = arg0.getTag().toString();
                        showDialog(0);
                    }
                });

                if((j % 2) == 0){
                    tr.setBackgroundColor(0xff00ffff);
                }
                tr.setTag(obj.getJSONObject(i).getString("id"));

                TextView td = new TextView(this);
                td.setText(obj.getJSONObject(i).getString("songtitle"));
                td.setTextSize(30);
                td.setTextColor(0xff000000);
                tr.addView(td, 350, 40);

                TextView td2 = new TextView(this);
                td2.setText(obj.getJSONObject(i).getString("artist"));
                td2.setTextSize(30);
                td2.setTextColor(0xff000000);
                tr.addView(td2, 350, 40);

                this.tblContainer.addView(tr);
            }

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

    }catch(ClientProtocolException cpe){
        Functions.showAlert(this, cpe.toString());

    }catch(IOException e){
        Functions.showAlert(this, e.toString());

    }

}


/**
 * 
 */
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated constructor stub
    super.onCreate(savedInstanceState);
    this.stateTmp = savedInstanceState;

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setTitle("Maestro - Playlist");
    setContentView(R.layout.playlist);

    // get room name(location)
    if(savedInstanceState == null){
        Bundle tmp = this.getIntent().getExtras();
        if(tmp != null){
            this.roomName = tmp.getString("room_name");
            this.serverAddress = tmp.getString("server_address");
            this.playerUsername = tmp.getString("player_username");
            this.layoutUsername = tmp.getString("layout_username");
        }
    }

    /*SideMenuClick changeMenu = new SideMenuClick();
    ImageButton sideMenuSonglist = (ImageButton) findViewById(R.id.songlist);
    sideMenuSonglist.setOnClickListener(changeMenu);

    ImageButton sideMenuKeyControl = (ImageButton) findViewById(R.id.keycontrol);
    sideMenuKeyControl.setOnClickListener(changeMenu);

    ImageButton sideMenuMylist = (ImageButton) findViewById(R.id.mylist);
    sideMenuMylist.setOnClickListener(changeMenu);

    getSong();
    ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
    sc.addView(this.tblContainer);

    TextView txt = (TextView) findViewById(R.id.pagedesc);
    txt.setText((this.page+1) + " / " + this.totalPage);
    txt.setTextColor(0xff000000);

    ImageButton next = (ImageButton) findViewById(R.id.next);
    next.setOnClickListener(changeMenu);

    ImageButton prev = (ImageButton) findViewById(R.id.prev);
    prev.setOnClickListener(changeMenu);*/

    drawLayout(true);
}

public void drawLayout(boolean isFirst){
    if(isFirst == true){
        // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        // setTitle("Maestro - Playlist");
    }


    SideMenuClick changeMenu = new SideMenuClick();
    ImageButton sideMenuSonglist = (ImageButton) findViewById(R.id.songlist);
    sideMenuSonglist.setOnClickListener(changeMenu);

    ImageButton sideMenuKeyControl = (ImageButton) findViewById(R.id.keycontrol);
    sideMenuKeyControl.setOnClickListener(changeMenu);

    ImageButton sideMenuMylist = (ImageButton) findViewById(R.id.mylist);
    sideMenuMylist.setOnClickListener(changeMenu);

    getSong();
    ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
    sc.addView(this.tblContainer);

    TextView txt = (TextView) findViewById(R.id.pagedesc);
    txt.setText((this.page+1) + " / " + this.totalPage);
    txt.setTextColor(0xff000000);

    ImageButton next = (ImageButton) findViewById(R.id.next);
    next.setOnClickListener(changeMenu);

    ImageButton prev = (ImageButton) findViewById(R.id.prev);
    prev.setOnClickListener(changeMenu);
}

public Context getRef(){
    return this;
}

public void changeActivity(int layoutId){
    Intent newActivity = new Intent();
    newActivity.putExtra("room_name", this.roomName);
    newActivity.putExtra("server_address", this.serverAddress);
    newActivity.putExtra("player_username", this.playerUsername);
    newActivity.putExtra("layoyt_username", this.layoutUsername);

    if(R.id.songlist == layoutId){
        newActivity.setClass(this, ListSongs.class);
        startActivity(newActivity);

    }else if(R.id.keycontrol == layoutId){
        newActivity.setClass(this, KeyControl.class);
        startActivity(newActivity);

    }else if(R.id.mylist == layoutId){
        newActivity.setClass(this, Mylist.class);
        startActivity(newActivity);

    }else if(R.id.prev == layoutId){
        if(page > 0){
            page--;
        }

        ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
        sc.removeView(this.tblContainer);

        getSong();

        sc.addView(this.tblContainer);
        TextView txt = (TextView) findViewById(R.id.pagedesc);
        txt.setText((this.page+1) + " / " + this.totalPage);


    }else if(R.id.next == layoutId){
        if(this.page < this.totalPage){
            page++;
        }

        ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
        sc.removeView(this.tblContainer);

        getSong();

        sc.addView(this.tblContainer);

        TextView txt = (TextView) findViewById(R.id.pagedesc);
        txt.setText((this.page+1) + " / " + this.totalPage);
    }
}

protected Dialog onCreateDialog(int id){

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.playlist_popup, (ViewGroup) findViewById(R.id.layout_root));

    ImageButton ib0 = (ImageButton) layout.findViewById(R.id.back);
    ib0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            selectedItem.setBackgroundDrawable(rowColor);
            dismissDialog(0);
        }
    });

    ImageButton ib1 = (ImageButton) layout.findViewById(R.id.del);
    ib1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0){
            Toast.makeText(getRef(), selectedItemIndex, 60000);
            HttpClient ajax = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(serverAddress + "/index.php?m=playlist&a=del&room=" + roomName + "&to=" + playerUsername + 
                    "&username=" + layoutUsername + "&id=" + selectedItemIndex);

            //Functions.showAlert(getRef(), serverAddress + "/index.php?m=playlist&a=del&room=" + roomName + "&to=" + playerUsername + 
            //      "&username=" + layoutUsername + "&id=" + selectedItemIndex);
            try {
                ajax.execute(httpGet);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            selectedItem.setBackgroundDrawable(rowColor);

            dismissDialog(0);

            // ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
            // sc.removeView(tblContainer);
            // sc.removeAllViewsInLayout();
            // sc.destroyDrawingCache();
            // tblContainer.removeAllViewsInLayout();
            // setContentView(R.layout.playlist);
            // setContentView(R.layout.playlist);
            // drawLayout(false);
            Intent newActivity = new Intent();
            newActivity.putExtra("room_name", roomName);
            newActivity.putExtra("server_address", serverAddress);
            newActivity.putExtra("player_username", playerUsername);
            newActivity.putExtra("layoyt_username", layoutUsername);
            newActivity.setClass(getRef(), Playlist.class);
            startActivity(newActivity);
            finish();

            // getSong();
            // sc = (ScrollView) findViewById(R.id.listcontainer);
            // tblContainer = new TableLayout(getRef());
            // sc.addView(tblContainer);
        }
    });

    ImageButton ib2 = (ImageButton) layout.findViewById(R.id.top);
    ib2.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0){
            Toast.makeText(getRef(), selectedItemIndex, 60000);
            HttpClient ajax = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(serverAddress + "/index.php?m=playlist&a=top&room=" + roomName + "&to=" + playerUsername + 
                    "&username=" + layoutUsername + "&id=" + selectedItemIndex);

            try {
                ajax.execute(httpGet);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            selectedItem.setBackgroundDrawable(rowColor);

            dismissDialog(0);

            ScrollView sc = (ScrollView) findViewById(R.id.listcontainer);
            sc.removeView(tblContainer);
            tblContainer = new TableLayout(getRef());

            getSong();

            sc.addView(tblContainer);
        }
    });


    layout.setLayoutParams(new LayoutParams(170, 90));
    layout.setMinimumWidth(0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    AlertDialog alertDialog = builder.create();
    alertDialog.setCancelable(true);
    alertDialog.setOnCancelListener(new OnCancelListener(){

        @Override
        public void onCancel(DialogInterface arg0) {
            // TODO Auto-generated method stub
            selectedItem.setBackgroundDrawable(rowColor);
            dismissDialog(0);
        }});

    return alertDialog;
}

public class SideMenuClick implements View.OnClickListener{

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        // changeList();
        changeActivity(arg0.getId());
    }

}

}
  • 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-27T17:34:35+00:00Added an answer on May 27, 2026 at 5:34 pm

    Views in Android have an Invalidate and PostInvalidate method which will at some point call the OnDraw method.

    So if you have populated a View with some data, you can make it redraw itself by invoking one of those two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that receives push notifications from C2DM server with a BroadcastReceiver.
I have an application that receives information from a database, and is used to
I have created a custom workflow activity that copies attachments from a case to
I have class that extends 'IntentService' - this class occasionally receives data from a
I have implemented an activity that plays media from a URL in Android. In
I have a activity that displays a number of elements from a list that
I have a system that receives input from the public each day. Each morning
I have a service that does database calls. The service receives a request with
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that contains several user editable items (an EditText field, RatingBar,

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.