Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use a progress bar when my app is reading data from a file ? Right before the start of the application
    primarykey
    data
    text
    <p>I am trying to write an application, where many rows of data are being extracted from a text file. This is done when i start the application. I want to show a progress bar to the user, when he clicks on the application in my applications screen. Right now there is a black screen for a brief period and then it shows the application data and displays the data. I want add a progress bar starting from 0 to 100 or just telling the user that my application is loading.</p> <p>Can anybody help me in adding a progress bar to code as i am new to this. I would appreciate all the help which is given to me. Thanks in advance.</p> <pre><code>public class MovieRatingsActivity extends ListActivity { private ArrayList&lt;Movie&gt; movies = new ArrayList&lt;Movie&gt;(); private LayoutInflater mInflater; private LruCache&lt;String, Bitmap&gt; cache; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializeUI(); } private void initializeUI() { mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); InputStream inputStream = getResources().openRawResource( R.raw.ratings); movies = Movie.loadFromFile(inputStream); setListAdapter(new RowIconAdapter(this, R.layout.listrow, R.id.row_label, movies)); } static class ViewHolder { TextView votesText; TextView movieText; ImageView icon; } /** Custom row adatper -- that displays an icon next to the movie name */ class RowIconAdapter extends ArrayAdapter&lt;Movie&gt; { private ArrayList&lt;Movie&gt; movies; public RowIconAdapter(Context c, int rowResourceId, int textViewResourceId, ArrayList&lt;Movie&gt; items) { super(c, rowResourceId, textViewResourceId, items); movies = items; } public View getView(int pos, View convertView, ViewGroup parent) { ViewHolder holder; Movie currMovie = movies.get(pos); if (convertView == null) { convertView = mInflater.inflate(R.layout.listrow, parent, false); holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.row_icon); holder.movieText = (TextView) convertView.findViewById(R.id.row_label); holder.votesText = (TextView) convertView.findViewById(R.id.row_subtext); holder.movieText.setText(currMovie.getName()); String votesStr = currMovie.getVotes()+" votes"; holder.votesText.setText(votesStr); Bitmap movieIcon = getMovieIcon(currMovie.getName(), currMovie.getRating()); holder.icon.setImageBitmap(movieIcon); Log.w("MVMVMVMVMVMV", "Creating row view at position "+pos+" movie "+currMovie.getName()); } return convertView; } } /** Creates a unique movie icon based on name and rating */ private Bitmap getMovieIcon(String movieName, String movieRating) { int bgColor = getColor(movieName); Bitmap b = Bitmap.createBitmap(48, 48, Bitmap.Config.ARGB_8888); b.eraseColor(bgColor); // fill bitmap with the color Canvas c = new Canvas(b); Paint p = new Paint(); p.setAntiAlias(true); p.setColor(getTextColor(bgColor)); p.setTextSize(24.0f); c.drawText(movieRating, 8, 32, p); return b; } /** Construct a color from a movie name */ private int getColor(String name) { String hex = toHexString(name); String red = "#"+hex.substring(0,2); String green = "#"+hex.substring(2,4); String blue = "#"+hex.substring(4,6); String alpha = "#"+hex.substring(6,8); int color = Color.argb(Integer.decode(alpha), Integer.decode(red), Integer.decode(green), Integer.decode(blue)); return color; } /** Given a movie name -- generate a hex value from its hashcode */ private String toHexString(String name) { int hc = name.hashCode(); String hex = Integer.toHexString(hc); if (hex.length() &lt; 8) { hex = hex+hex+hex; hex = hex.substring(0,8); // use default color value } return hex; } /** Crude optimization to obtain a contrasting color -- does not work well yet */ private int getTextColor(int bg) { int r = Color.red(bg); int g = Color.green(bg); int b = Color.blue(bg); String hex = Integer.toHexString(r)+Integer.toHexString(g); hex += Integer.toHexString(b); int cDec = Integer.decode("#"+hex); if (cDec &gt; 0xFFFFFF/2) // go dark for lighter shades return Color.rgb(0, 0, 0); else { r = (r+128)%256; g = (g+128)%256; b = (b+128)%256; return Color.rgb(r,g,b); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload