Horizontal Progressbar via code

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Horizontal Progressbar via code

Postby timhoeck » Sun Jan 18, 2009 7:23 pm

I am trying to modify the IconifiedTextView (http://www.anddev.org/iconified_textlist_-_the_making_of-t97.html) to include a horizontal progressbar. I setup a horizontal progressbar before, but only by modifying the style of the view in the xml for the layout.

How can I modify the style of a View created during runtime?
Last edited by timhoeck on Tue Jan 27, 2009 6:20 am, edited 1 time in total.
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Top

Postby timhoeck » Tue Jan 27, 2009 6:19 am

Followup..

While I still haven't exactly found a way to just change the style of a view during runtime (i.e. my progress bar to horizontal).. I worked around this by modifying the view creations in IconifiedTextView code. Instead of creating new (Default) Text and Image views in IconifiedTextView, I pull in a layout from a precreated xml file using LayoutInflator...

Code: Select all
          View row = new View(context);
          LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          row = inflater.inflate(R.layout.item, null); 
          addView(row);
         
          TextView title = (TextView) row.findViewById(R.id.txtTitle);
          title.setText(aIconifiedText.getText());
         
          ImageView icon = (ImageView) row.findViewById(R.id.imgStatus);
          icon.setImageDrawable(aIconifiedText.getIcon());
         
          ProgressBar progbar = (ProgressBar) row.findViewById(R.id.ProgressBar01);
          progbar.setProgress(aIconifiedText.getProgress());


Does that make sense? This may be overdoing it, but at least it works for me. Now I get the benefit of getting to see and modify the look of my rows ahead of time, in an XML layout form,, and get my horizontal progress bar.

I would still like to know if there is a way (even if it involves LayoutInflator) to change the style of a view, i.e. set runtime generated views layout/theme to a precreated xml layout... something like:

View v;
v.setStyle(R.layout.item);

I know that you can use setTheme() in an activity to change the theme of that activity, but does this apply to views as well?
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Postby mrsack » Wed Jul 22, 2009 7:03 am

I'm still looking for a way to do this with code only, so without having to use ANY XML. This is a quick easy way to do it in XML, so I would hope there would be a simple way to set the style with code as well since for pretty much all other views you can set most variables. Any ideas?
mrsack
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 10, 2009 2:06 am

Postby mrsack » Wed Jul 22, 2009 6:08 pm

Ok, I figured it out for anyone else who needs the same thing

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ProgressBar pb = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
mrsack
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 10, 2009 2:06 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests