Android :: Apply Styles To My Views At Runtime Dynamically?
Aug 13, 2010I'd like to dynamically apply styles to my views at runtime.
Is there any method like View.setStyle(int style)?
I'd like to dynamically apply styles to my views at runtime.
Is there any method like View.setStyle(int style)?
I am new to Android app. development. I need to change the existing style at runtime or can create new styles at runtime and I need to apply it for my buttons and textviews.
View 3 Replies View RelatedMy query is regarding on whether we can apply dynamically themes in android,like what we do with our phones in which we can select a theme and the same theme gets applied all across the phone.Is there a way to do this in android? (I am able to change the default theme by hardcoding in the code (styles.xml),but I need to know how we can we set themes dynamically. I saw the Android phone,but there is no Setting where we can set the Theme.)
View 5 Replies View RelatedI am storing the required test.jar file in the /sdcard. I want to load it dynamically at runtime and want to execute a function xyz() resides in that. For this purpose I had written following code:
But got ClassCastException : dalvik.system.PathClassLoader
Following is my code ,
import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader;
import android.app.Activity; import android.os.Bundle; import android.util.Log;
public class Collabera extends Activity {
/** Called when the activity is first created. */
private static final Class[] parameters = new Class[] { URL.class };
public static void loadURLClass(String classPathURL) throws IOException {
File f = new File(classPathURL);
URL url = f.toURL();
URLClassLoader systemLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class systemLoaderClass = URLClassLoader.class;
try { Method method = systemLoaderClass.getDeclaredMethod("addURL", parameters);
method.setAccessible(true);
method.invoke(systemLoader, new Object[] { url });
} catch (Throwable t) { t.printStackTrace();
throw new IOException( "Error, could not add URL to system classloader");
} }
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("See","**************Before Loading Class Path**************");
try { Class.forName("test.Test1");
} catch (ClassNotFoundException e) { System.out.println(" Test Class Not Found ....");
} Log.i("See","**************After Loading Class Path**************");
try { loadURLClass("//sdcard//test.jar");
Class c = Class.forName("test.Test1");
Log.i("See"," Test Class Found ....");
Method method = c.getMethod("xyz", null);
Object o = c.newInstance();
String s = (String) method.invoke(o);
Log.i("See","Got method: " + s);
} catch (ClassNotFoundException e) { System.out.println(" Test Class Not Found ....");
} catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();
} } }
My application requires 2 screens and for this I have created two different XML layout files using RelativeLayout. One layout file loads whenever I run my Activity. Now I want to load the second layout on to the same Activity , when user click on a button in OptionsMenu and also when user press Back button the first screen loads instead of exiting the application. So that i don't need to create another Intent in my application.
View 3 Replies View RelatedI have an xml layout that will display a grid made up of textviews within tablerows. The textview names are cell00, cell01, etc. At runtime, my program will determine which cell needs to be changed.
Is there a way get format a name so that it can be passed to the findViewById method at runtime? For example, if cell00 is needed, how can I generate the parm in this code?
TextView currcell = (TextView) findViewById(R.id.cell00)
Something like "cell"+00 doesn't compile because the findViewById method doesn't accept a String type. I don't want have every textview name in the grid hardcoded in the program - there must be a better way.
I am using and android 2.2 phone for testing and getting an error.
07-27 01:24:55.692: W/System.err(14319): java.lang.ClassNotFoundException: com.shoaib.AndroidCCL.MyClass in loader dalvik.system.DexClassLoader@43abbc20
First I wrote the following class:
Code:
package org.shoaib.androidccl;
import android.util.Log;
public class MyClass {
public MyClass() {
Log.d(MyClass.class.getName(), "MyClass: constructor called.");
}
public void doSomething() {
Log.d(MyClass.class.getName(), "MyClass: doSomething() called.");
}
}
And I packaged it in a DEX file that I saved on my device's SD card as `/sdcard/testdex.jar`.
Then I wrote the program below, after having removed `MyClass` from my Eclipse project and cleaned it:
Code:
public class Main extends Activity {
[MENTION=1299008]supp[/MENTION]ressWarnings("unchecked")
[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
[code]....
I'm trying to learn how to build apps for Android. The first simple app, which will become a component of a bigger app I hope to build, is to have a button on the screen where, when tapped, it adds something new to the view. For instance: Imagine a layout that only has a button:
[Create!]
When that button is pressed, the view gets a new row added to it:
[Create!]
A Something!..............
In my main.xml layout file, I define a FrameLayout. Then in another layout file (say overlay.xml), I define another layout.
At runtime (onCreate) I want to create a new View object, set it's layout with overlay.xml, and add it to the frame dynamically. I need access to the elements of the overlay, to change text etc.
I use a LinearLayout and first I have a MapView and below the map I have a TableLayout with informations fields.
Now I would like to add additional information fields (e.g. a new TableLayout) when the user select a specific menu item on the Options Menu. I would like to have these fields either between the MapView and the TableLayout, or on top of the bottom area of the MapView.
How can I add this TableLayout with additional information fields dynamically after the user has selected a menu item? How can I show it below the MapView or on top of the bottom area of the MapView?
Dynamically i am creating the linear layout and adding the views to linear layout every 5 sec i need to update data to linear layout from db when i check logger output it is adding to linear layout but gui it is not updating for every 5 sec updation i am using scheduleatfixed timer task.
View 2 Replies View RelatedIs there (or should there be), a generateId() method for dynamically generated Views? Take the RadioGroup example in APIDemos|App|Views. Radio buttons are added dynamically. For each button, you have to call setId(). To be notified when a radio button is selected, you register a onCheckedChange listener on RadioGroup and the callback method is oncheckedChange(RadioGroup, int checkedId). Since we are notified only the id of the checked view, shouldn't there be a way to uniquely generate the id? Say, a View.generateId() method... In the example, the ids are statically defined in ids.xml. However this limits the number of radio buttons. I have a real world example too: a Radiogroup with each choice representing a Wifi hotspot. So one cannot know in advance the number of hotspots.
View 10 Replies View RelatedI have a remove assistant app, which allows customers to perform a subset of functions of a desktop application, untethered. Results are communicated back & forth via messages left at a license server. In order to have a single source for the logic of the assistant, yet run on multiple platforms (Swing, MIDP, & Android), I write a driver composed of Database, Network, & Display pieces.
The Android driver is nearly complete, but I run into a brick wall when it comes to Tabs. All views are instanced calling code, not XML defined. I already have the view before I try to add it.
I tried sub- classing TabHost:
CODE:.................
As is shown in the code, it errors in setup. Looking further down in setup() I will also get this exception too: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent
Is there a way to trick setup() into instancing me mTabWidget & mTabContent members?
I am trying to load textView and CheckBox view dynamically to a LinearLayout. i am getting some Orientation problem while doing the same.I want these two view in a single row but i its coming as in different raw.
Below is may code:
CODE:..............
layoutxml is
CODE:..................
To use as an example: lets say that I have 2 EditTexts and one Button that I'm using as a login form. I want the EditTexts to be the same size, one after the other, with the login Button half their widths. Something like this:
The only way that I've been able to find to make the button 1/2 the width (but still maintain it's dynamic sizing) is to use a TableLayout with an empty view as the first field. Something like this:
CODE:.............
That feels like a god-awful hack and there has GOT to be a better way. Do you know of one?
I am trying to dynamically create a interface using a relative layout. I would like to align different views with each other and am finding the need to know the id of a previously created view so that I can use them in subsequent layout params.
Is there a preferred or best way to generate or create ids for views that are created dynamically?
How to apply background color to listview dynamically in Android?
View 1 Replies View RelatedI have a ViewGroup that gets inflated dynamically. I have set Id's to all the inflated views. I am still not able to retain the inflated ViewGroup whenever the orientation is changed. Any particular check that i am missing here ?
View 1 Replies View RelatedI have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.
The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.
The problem is that when the background changes from the default greyish, all the Views in the CustomView (ImageView and TextViews) still have their greyish background and thus creates very ugly greay boxes on top of the now redish background.
What is the best way to solve that problem? I hoped that such things were handled automatically (as it is done in for example .NET), but I was wrong it seems.
1) I am developing my app in Eclipse 3.4.1 with Android (ver 1.1_r1) plugin. My app compiles and executes without errors when using the Eclipse IDE.
However, when I export my app (unsigned) using Eclipse (via {select project} >right-click>Android tools>export unsigned application package), sign it, and try to run it on the Emulator, it throws a runtime error when I try to update my sqlite database, at which time the specific error created is: SQLite error#14, unable to open database. It is able to read from the database without problems. (I have also verified that the database is: open, is not readonly, is not locked by another thread, is not in the middle of a transaction.)
I have limited experience, but this seems more like a "system" problem given that the app works OK in Eclipse IDE but then fails as an exported/signed apk. Some googling of SQLite resources revealed a similar error on a non-Android platform which was fixed by: "Set your permissions correctly on /var/tmp, or whatever directory you are using to hold temporary files".
Does Android have temporary files, and if so how does it handle permissions on temporary files? Is there a way to check or set these permissions to see if this fixes my problem here?
2) Not sure if it is related, but after I have run the exported/signed app which causes the runtime error, if I reboot the Emulator, and try to run the program using the Eclipse IDE , the program fails with the same exact error. PLUS I also noticed the following error message while the program is installing/running: 03-01 22:22:29.282: ERROR/PackageManager(53): Package com.northwestradiology has mismatched uid: 0 on disk, 10019 in settings; read messages:
I can restore the Eclipse version of my program to be able to execute without runtime errors by utilizing the -wipe-data option for the emulator. But note that if I run my signed APK using an emulator created with the -wipe-data option, it still throws the runtime error listed above...
I am implementing a music player application in Android. My play list selection screen is implemented as a tab selector widget which contains a ListActivity inside each of the tabs: Artist, Albums, Songs.
I want to update the ListView in each of the ListActivity when I delete an item from any of the lists.
i.e. When I long press an item in the Artists list a context menu is drawn with "Delete Artist"
And it should delete all the songs from this artist in the Songs ListView, delete all the albums by this artist in the Albums ListView, and finally delete the entry for the artist in the Artist ListView.
Each of the ListActivity has its own fillData() method, which updates the ListView when the button in the context menu is pressed.
How can I call the fillData() method of the Albums ListActivity after I update the ListView inside of the Artists ListActivity?
I want to populate a table, defined in layout xml file through the programmatic way. I have define Table with a single row defining its header, with all the attributes set. Now i want to know a way so that i can just replicate that header row in the table with new content.
I tried using inflator inflate(int,view) method, but at runtime it showed up with error.
Here is the XML code for the layout file defining the table
CODE:.................
I have the following XML code:.................
The idea is to change the views, whenever I press one of the radio buttons. When I press a button the first time everything works out fine, but the second time I press a button, I get an IllegalStateException, and I can't quite see why I'm getting this.
Also, the Activity seems to set all my global variables to null, which is why I have to create them every time I switch from portrait to landscape or vice versa. So I would like to know if there is a way I can save my views in the Bundle, or any other way in which I can permanently save my views, so I don't have to add or create them every time, I flip the phone. And whenever I flip the phone, it seems that it rereads the main XML file, causing the RadioGroup to be set to 2D even if the 3D button is checked. This is because I've said the 2D button to be checked from when the app is first created, but I would like to also save the state of that RadioGroup.
How do you align views relative to the "middle" part of another view? I think it is best explained with a pic of the UI I'm trying to create in android.
View 2 Replies View RelatedIs there any way to query a root view of an activity for all of its child views even before the root view or its children have been inflated? I guess what I'm looking for is whether a view knows ahead of time what children it will have before it gets inflated, and can I get that list in some way. Bizarre I realize, but I think it will help me with some unconventional automation testing I'm working on. I haven't found anything in the API like this.
View 1 Replies View RelatedLet's say I have a LinearLayout, and I want to add a View to it, in my program from the Java code. What method is used for this? I'm not asking how it's done in XML, which I do know, but rather, how can I do something along the lines of (One View).add(Another View) Like one can do in Swing.
View 2 Replies View RelatedFor Style and Thems defination, CSS is considered to be a better standard...(as it has seen many revisions and widely used already in the web areas).. Any reason, why Android using XML approach as opposed to CSS.. Are there any plans of support of CSS too in future..
View 5 Replies View RelatedI want to enable different themes in my app. Some elements need "special" variations, like, for example, a headline TextView. Lets say for the example, in theme A, I want the headline yellow on black, in theme B red on white, while the default TextView uses black on white and vice versa.
Now, I can style the default TextView pretty easy by using <item name="android:textViewStyle"> with a different TextView style in each Theme style.
For example:
CODE:............
But how can I do it with the headline? As far as I know, I can use style="..." in the layout XML. But there, I can only use an item style like "headlineForBlack", which would ignore the current theme, while I'd rather need something like "style 'headline' for the current theme".
I have defined some attributes in my view and I can assign them like:
CODE:................
This works. But when I want to do the same thing with styles.xml:
CODE:.................
I get "No resource found that matches the given name".
Given a widget and a int that references a style (defined in my res/ values/style.xml), what is the 'correct' way to programmatically apply the style to the widget?
Up until now I've been hacking this by...
CODE:..................