Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Android


Android :: XML Layout Of Custom Component

I have created a simple class named Panel which extends the SurfaceView class and does some drawing in the onDraw method. When I use it from the code it works fine. For example this works as expected:
public void onCreate(Bundle savedInstanceState) {
setContentView(new Panel(this)); ....

However when I try adding this component from an xml layout the program crashes:
XML file (main.xml):
<?xml version="1.0" encoding="utf-8"?> <org.anddev.Panel android:id="@+id/panel" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android=""/>

public void onCreate(Bundle savedInstanceState) {

Error msg: Sorry!
The application Test (process org.anddev) has stopped unexpectedly. Pleas try again.
I can not figure out why the same class works when created in one way and doesn't work when created in another.

View Complete Thread with Replies

Sponsored Links:

Related Forum Messages:
Android :: Find View Returns Null For Custom Component In Layout
I have a res/layout/main.xml including these elements and others:

<some.package.MyCustomView android:id="@+id/foo" (some other params) />
<TextView android:id="@+id/boring" (some other params) />
In my Activity's onCreate, I do this:
(TextView) boring = findViewById(;
// ...find other elements...
MyCustomView foo = (MyCustomView) findViewById(;
if (foo == null) { Log.d(TAG, "epic fail"); }

The other elements are found successfully, but foo comes back null. MyCustomView has a constructor MyCustomView(Context c, AttributeSet a) and a Log.d(...) at the end of that constructor appears successfully in logcat just before the "epic fail".
findViewById() returns null for custom component in layout XML, not for other components. Why is foo null?

View Replies!   View Related
Android :: Can Animate - Scale - Just One Component Of Android Layout And Have Layout Update During Animation
Imagine I have a toolbar implemented as a horizontal LinearLayout as follows:

[___Button1____] [___Button2___] [___Button3___] [___Button4___]

When someone clicks on Button2, I want the toolbar to change to:

[___Button1____] [___________Button2___________] [___Button3___]

The toolbar should transition from the first state to the second state through a smooth animation. I would like to use a scale animation on Button2, and while that is happening, Button3 and Button 4 should move to the right (while the animation is going on). At the end of the animation (or maybe during), I will fade Button4 out.

Question: How do I achieve an animation of the layout of the toolbar such that only one component (i.e. Button2) is being scaled while the others are not being scaled - the layout is simply updated during the animation of Button2.

I looked at LayoutAnimationController, but it does not appear to allow me to either:

1. specify different animations for the different components, OR

2. indicate that only animate one component and don't animate the others.

I can't scale the entire toolbar because that distorts Button1/3/4 which I don't want.

View Replies!   View Related
Android :: Droid Layout : Is Reusable Component UI Possible?
I'll preface this with, I've just started learning Android so be gentle.
I come from an ASP.NET / Silverlight background so I was looking for something along the lines of controls.

I want to reuse a layout (a ListView item template) in other layouts.

Such that in my other layouts I can just add <myListItem /> to show it.

Is this, or anything like it possible? or are there better ways?

View Replies!   View Related
Android :: Create Custom Component Using Inflate
I'm trying to create a component using an xml layout file. I defined a layout with some custom attributes. This layout is inflated when user add it inside another layout. My problem is I don't know the parent, so I pass null for the parent viewgroup when I call inflate method. I think that's the reason why I see anything in my view. Do you know how can I do (I don't want to redefine onDraw method because I use existing component). Below my xml layout and my custom class.

<RelativeLayout xmlns:android="" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/img_btn_option" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/txt_btn_option" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@id/img_btn_option"
android:textColor="@color/font_white" android:textStyle="bold"/>
</RelativeLayout> public class ButtonOptionsView extends View {
public ButtonOptionsView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater li =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout vg =(RelativeLayout)li.inflate(R.layout.button_option, null);
TypedArray ta = getContext().obtainStyledAttributes(attrs,R.styleable.ButtonOption);

View Replies!   View Related
Android :: Custom Component ImageView Override
I've made a little test component that overrides ImageView, called myImageView, and prints some text and an arrayList of Doubles over whatever image is specified in the related xml. However, right now, the text and Doubles that are drawn over the image are defined within the myImageView class. Is there a way to pass the data from the main onCreate function to the myImageView class before the layout is drawn?

I'm new to OO programming, but based on my understanding of this:
It's possible because ImageView is just like any other class. This leaves me with two initial guesses:
1. I could generate my test data in the main onCreate, and store it in the array's xml file, and then read that xml file with myImageView,
2. I could extend view instead of ImageView, but because of my new- ness, then I would lose the ability to use it in an xml layout sense - and that's what I really want.

View Replies!   View Related
Android :: How To Change Custom Component Height Programmatically?
I've prepared custom component based on LinearLayout. Whole component is defined in XML. Currently to use it you have to write:
android:layout_height="44dp" />

Is it possible to set width and height in the java constructor? So it would be possible to write just:
< />
I've tried to modify and set LayoutParams, but it didn't work for me.

View Replies!   View Related
Android :: Custom Compound Component Rare Exception
I've created custom compound component and observe very strange exception (google says nothing about it). Custom component rare exception: Parser is not a BridgeXmlBlockParser!

It is very simple:
public class MyTabber extends LinearLayout {
.. public MyTabber(Context context) { super(context);
Init(context); }

View Replies!   View Related
Android :: Views In Custom Compound Component Not Inflated
I have made a Custom Component in XML, consisting of a button with an imageview stacked on top of it:


Extract of java source code:
public class ClearableCaptionedButton extends RelativeLayout implements OnClickListener {
public ClearableCaptionedButton(Context context, AttributeSet attrs) { super(context, attrs);
// some stuff that works fine
} ..
protected void onFinishInflate() { super.onFinishInflate();
mButton = (Button) findViewById(;
mClear = (ImageView) findViewById(;
mButton.setText(""); // error here: mButton == null

My problem is similar to this one. When I try to find the views inside the custom compound, findViewById returns null. But, as you can see, i already added super(context, attrs); to the constructor. I am using the custom component directly in xml layout, like this:

<!-- some stuff -->

View Replies!   View Related
Android :: Creating Custom Component Which Supports Voice Recognition
I'd like to create a custom component which supports voice recognition. (Custom Component which displays voice recognition button if available). It will primarily be an extended EditText which should show the microphone button for voice recognition if it is available. I wanted to to look at the search app-widget on the homescreen but I don't find it in the source. This is intended to use the voice recognition as some sort of dictation device, i.e. the user does not have to type but use his voice instead. So could anyone please point me in some direction?

View Replies!   View Related
Android :: Expanding ListView Custom Component With Button Click
I'm developing a small application in with a list view filled with a compound component. This component has two text view and one button inside. One of the text view is invisible and when the button is clicked it should appear. I can show the list but i can't make the textview visible when the button is clicked. Here is the xml of the component: And this is the ArrayAdapter that fills the list:

public class AddressAdapter extends ArrayAdapter { int resource;
RelativeLayout placeView;
EditText addressText;
public AddressAdapter(Context _context, int _resource, List _items) {
super(_context, _resource, _items);
resource = _resource;
} private OnClickListener buttonClick = new OnClickListener() {
public void onClick (View v) {
int i = placeView.findViewById(;
} };
private void visibility(int i) {
// TODO Auto-generated method stub switch(i) {
case(View.GONE): { addressText.setVisibility(View.VISIBLE);
} case(View.VISIBLE): { addressText.setVisibility(View.GONE);
} } }
@Override public View getView(int position, View convertView, ViewGroup parent) {
Item item = getItem(position);
String name = item.getName();
String address = item.getAddress();
if (convertView == null) {
placeView = new RelativeLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, placeView, true);
} else { placeView = (RelativeLayout) convertView;
} TextView nameText = (TextView)placeView.findViewById(;
Button button = (Button)placeView.findViewById(;
addressText = (EditText)placeView.findViewById(;
return placeView;
} }

View Replies!   View Related
Android :: Including Custom Component / View No Longer Shows Up
The app I'm working on has 4 tabs, 3 of which share many features, including a navigation bar a the bottom with Back, Edit, and Map buttons. There is exactly the same xml in all 3 layouts, so I'm trying to DRY this out by extracting that xml into a separate component, including it, and then going from there. Previously I had:

<RelativeLayout xmlns:android=""
<RelativeLayout xmlns:android=""
android:id="@+id/showedit_toolbar" style="@style/showItemToolbar">
<ImageButton android:id="@+id/show_person_back_button"
<Button android:id="@+id/show_person_map_button"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_person_edit_button"
android:text="edit" android:layout_toLeftOf="@id/show_person_map_button"/>
<ScrollView xmlns:android=""
// Lots more layout omitted

I extracted out the bit that's repeated into an xml file called show_toolbar.xml, changing the names of variables to make it more generic across the 3 views
<RelativeLayout xmlns:android=""
android:id="@+id/show_toolbar" style="@style/showItemToolbar">
<ImageButton style="@style/blackToolbarButton"
<Button android:id="@+id/show_map_button"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_edit_button" style="@style/blackToolbarButton"
android:text="edit" android:layout_toLeftOf="@id/show_map_button"/>

Then from within my original layout file, I replaced that big block of code with
<RelativeLayout xmlns:android=""
android:layout_height="fill_parent" android:layout_width="fill_parent">
<include android:id="@+id/show_toolbar" layout="@layout/show_toolbar"/>
<ScrollView xmlns:android=""
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_above="@id/showedit_toolbar" style="@style/CoinLightTheme">

Now, the problem is that the view no longer shows up. Including Custom component causes it to be hidden behind main viewI can still click the buttons and they respond (i.e. if I click in the corner where the button should be, it still works), but I cannot see the buttons or bar onto which they were drawn. I cannot find very good documentation on how Include is supposed to work, so perhaps I am using it incorrectly.

View Replies!   View Related
Android :: Android - Writing Custom (Compound) Component
The Android app I'm currently developing has a main activity that has grown quite large. This is mainly because it contains a TabWidget with 3 tabs. Each tab has quite a few components. The activity has to control of all those components at once. So I think you can imagine that this Activity has like 20 fields (a field for almost every component). Also it contains a lot of logic (click listeners, logic to fill lists, etc). What I normally do in component based frameworks is to split everything up into custom components. Each custom component would then have a clear responsibility. It would contain it's own set of components and all other logic related to that component.

I tried to figure out how this can be done, and I found something in the Android documentation what they like to call a "Compound Control".
(See and scroll to the "Compound Controls" section) I would like to create such a component based on an XML file defining the view structure.

In the documentation it says:
Note that just like with an Activity, you can use either the declarative (XML-based) approach to creating the contained components, or you can nest them programmatically from your code. Well, that's good news! The XML-based approach is exactly what I want! But it doesn't say how to do it, except that it is "like with an Activity". But what I do in an Activity is call setContentView(...) to inflate the views from XML. That method is not available if you for example subclass LinearLayout. So I tried to inflate the XML manually like this:

public class MyCompoundComponent extends LinearLayout {
public MyCompoundComponent(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this);
} }

This works, except for the fact that the XML I'm loading has LinearLayout declared as the root element. This results in the inflated LinearLayout being a child of MyCompoundComponent which itself already is a LinearLayout!! So now we have a redundant LinearLayout in between MyCompoundComponent and the views it actually needs. Can somebody please provide me with a better way to approach this, avoiding having a redundant LinearLayout instantiated?

View Replies!   View Related
Android :: Android - Showing Dialog From Custom Component
I am writing a custom component (derived from a relative layout) which has to show a dialog. Is there a way to do this using callbacks like oncreatedialog or onpreparedialog? if not: if i have to create the dialog outside oncreatedialog, i have to "attach it to an Activity with setOwnerActivity(Activity)". How can the custom component access the activity it is used in, when it is used in the activity's xml-layout and not created from code?

View Replies!   View Related
Android :: Android - Defining Custom Component Layouts In XML
I'm reading the android developer docs on creating custom components and one thing that's unclear, is whether you can define the layout of your component using xml and then reuse that across class libraries. like, say for instance, I want to create a class library called myComponents, and in there i want to have myTehAwesumsWidget or whatever, and i want the layout to be defined in xml, can i include that xml in the referenced class library?

View Replies!   View Related
Android :: Android Custom Component Properties
I have made an component for Android, which uses two drawables. Using static values for the drawables in the code, the component works but now I want to declare the values in the properties (XML) does anyone know how to do this? Is there a way to do this without using the attrs.xml?

View Replies!   View Related
Android :: Button With Custom XML Layout
Is it possible to create a button with a custom xml layout? Now I want to use this on a button. Anyone know how I can do this? I was thinking if I had file that extended Button. And then setView( R. layout. mylayout.xml); but that was to easy, and it clearly not working

View Replies!   View Related
Android :: Add Custom View To XML Layout
Currently, I am creating a custom View class (DrawView) that inherits the View class and adding to my activity programatically by using RelativeLayout and LaoutParams etc. But is there an easier way to do this by adding my DrawView to the layout XML file?

View Replies!   View Related
Android :: How To Get A View From A Custom Layout
I've created a custom view via .xml file, and I wanted to add it as a a contentView to an alert Dialog usinf a dialogBuilder:


The problem is...I can't get my view from my custom layout... I only have an id (int)...

I tried Resource.getLayout(int) => it returns an xmlParser... not very usefull ...

finally the solution I comes up is so disgusting ( it worked but ... let's have a look)


How can I do that easily without using such a disgusting way... ?

View Replies!   View Related
Android :: Custom View With Layout?
I am trying to do is to embed a custom view in the default layout main.xml:


As you can see the class is called com.lam.customview.CustomDisplayView, with the id of custom_display_view1. now in the com.lam.customview.CustomDisplayView class, i want to use another layout called custom_display_view.xml because i don't want to programmatically create controls/widgets.

Custom_display_view.xml is just a button and an image, the content of which i want to change based on certain conditions:


I tried to do:


But got this error, "03-08 20:33:15.711: ERROR/onCreate(10879): Binary XML file line #8: Error inflating class java.lang.reflect.Constructor ".


But got this error, "03-08 20:28:47.401: ERROR/CustomDisplayView(10806): Resource ID #0x7f050002 type #0x12 is not valid "

Also, if i do it this way, as someone has suggested, it's not clear to me how the custom_display_view.xml is associated with the custom view class.

View Replies!   View Related
Android :: Custom View In Xml Layout
I've created my own view by creating a subclass of the SurfaceView class.

However I can't figure out how to add it from the xml layout file.

My current main.xml looks like this:


What have I missed?

My view looks like this


And it works fine like this:


But nothing happens when trying to use it from the xml.

View Replies!   View Related
Android :: Dismiss Dialog With Custom Layout
I have a dialog with a custom layout, and I try to close it when I press a button:
private void showAboutDialog() {
dialog = new Dialog(MainMenu.this);

LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(;
Button closeButton = (Button) layout.findViewById(;
closeButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { dialog.dismiss();
} } );
But it doesn't work.

View Replies!   View Related
Android :: Linear Layout And Custom Dialog
The button doesn't show in this layout(code below),image and textview are shown. I tried using relative layout but that doesn't help either.

I'm testing it on 1.5 emulator.


View Replies!   View Related
Android :: Writing Custom Linear Layout
I have a custom layout that draws a transparent rounded rectangle beneath its children. The problem is when I try to add it to my xml file, it doesn't show up. Also, when I try to add parameters to it (i.e. android:layout_width) the popup shows that none of them are available. The same thing happens to any child views I add. public class RoundRectLayout extends LinearLayout
{ private RectF shape;public RoundRectLayout(Context context)
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}public RoundRectLayout(Context context, AttributeSet attrs)
{ super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{shape = new RectF(0, 0, w - 5, h - 5);
super.onSizeChanged(w, h, oldw, oldh);
protected void dispatchDraw(Canvas canvas)
Paint temp = new Paint();
canvas.drawRoundRect(shape, 10f, 10f, temp);

View Replies!   View Related
Android :: Listview Custom Row Layout - Tried Many Combinations
I am having trouble getting my layout to give me result I need, I already tried many options and it seems that I'm doing something wrong or completely missing something.

I have a listview with a custom row layout I can't seem to working although it shouldn't be complex. I need of the list row to insist of:

Icon -- title text (bigger and bold) with a short multi line text under the title -- ImageButton

My problem in most of my tests is the icon to the right usually doesn't appear, I guess my center group grows and takes all the space of the button. My last failed attempt was with a Relative Layout, didn't have too much luck with a Linear Layout either.

Here is the row XML:


View Replies!   View Related
Android :: Custom Typface In Listview Row Layout
I am running a sqlite query and binding the returned data to a ListAdapter.

I have used the following example

ListActivity | Android Developers

However, having defined a seperate layout for the rows I cannot change the typeface for textview text1 to a custom one from assets

Here is the row layout


Here is the code from the andriod tutorial


We'll define a custom screen layout here (the one shown above), but typically, you could just use the standard ListActivity layout. setContentView(R.layout.custom_list_activity_view) ;

Query for all people contacts using the Contacts.People convenience class. Put a managed wrapper around the retrieved cursor so we don't have to worry about requerying or closing it as the activity changes state.


Now create a new list adapter bound to the cursor. SimpleListAdapter is designed for binding to a Cursor.

Specify the row template to use (here, two columns bound to the two retrieved cursor rows). mCursor, // Pass in the cursor to bind tonew String[]{People.NAME, People.COMPANY}, // Array of cursor columns to bind to. new int[] {,}); // Parallel array of which template objects to bind to those columns.


View Replies!   View Related
Android :: Populating Custom Layout From Xml Resource
I have created a custom list item layout just like in this article

Each list item has icon, title and summary.

I would like to declare an xml resource that would provide data for that list. Just like you use <string-array> to populate the list using ArrayAdapter<String>.

The simple ArrayAdapter<String> can be populated from:


I need each <item> to have icon, title and summary. Somewhat similar to:


I would use <menu> but menu doesn't have summary if I'm not mistaken.

View Replies!   View Related
Android :: Refering To A Custom View In A Layout XML?
I am trying to refer to a custom View in the helloWorld XML layout but I get the following exception:
Error inflating class

However, I am able to instantiate the view and add it to the main content view manually. The custom View is built from it's own XML layout. How do I get this to work?


View Replies!   View Related
Android :: ListAdapter - Cursor - Custom Layout?
I'm experimenting with the Android platform, and I'm beginning to love it, but right now I'm stuck, at this cursor/list adapter problem-thing.

The thing is, that I request a function, returning a data object, with several properties I'd like to map to different TextView's.

My list_item.xml


So what I would like to do is: Map a property of an array of objects to several fields in the file.

View Replies!   View Related
Android :: Tell My Own Custom Spinner Layout To Use Theme?
How to I tell my own custom Spinner Layout to use my Theme? code...

View Replies!   View Related
Android :: Use Values Declared In XML On My Custom Layout?
Im creating a custom layout and I want to use the text declared in the layout.xml file in my layout.

Like when I create a TextView in XML and set android:text=@string/text1 when I run the app text view automatically loads the text from android:text. So how can I access attributes declared in the layout XML file in my custom component.

View Replies!   View Related
Android : Design A Custom Control / Use It In Xml Layout?
I understand how to create a custom Android control, and I believe I understand how to pull attributes for it from the Xml layout. I don't know, however, how to get any children elements from it. Here's a visual example of what I'm trying to accomplish: public class Menu extends LinearLayout. When my Menu is created, how do I get references to the two MenuItems. Code...

View Replies!   View Related
Android :: Custom Widget - Attributes In The Layout Xml Files
I have defined custom views in the various layout .xml files. However, all the layouts are using the Linear Layout - put the content would vary.

I would like to create my own widget tag something like <com.mypackage.MyLinearLayout />, I would like to pass the layout as a param to the <com.mypackage.MyLinearLayout layout="@layout/simple.xml" />

How to define new attributes to the custom widgets ? Simply defining a getter/setter method would work or is there any other references.

View Replies!   View Related
Android :: Add Custom Views To Linear Layout Object
I have a set of custom views that I would like to add to a LinearLayout object. However, the first object I add to the layout (I do this dynamically, during runtime) has a OnMeasure method that tries to get as much space as possible resulting in that it get's all the space LinearLayout object. This is correct behavior, but when I then add more objects following that I want the allocated area for the first object to decrease so the others will fit. As it is now, each following object will get zero space, and hence won't be visible.

View Replies!   View Related
Android :: Drawing Children In Custom Linear Layout
I have a linear layout that I have overridden because I want to > dynamically add other views to it. I am trying to add some textviews > to it and I call addViewToLayout in the onLayout method. Can't you just add your views to the layout using addView()? I have one custom LinearLayout and this is what I do and it works fine. No need to override onLayout() or onDraw(). Maybe try that

View Replies!   View Related
Android :: Creating A Custom Image Based Layout?
Is it possible to create a layout based on (background) images? For example, there is well know app called Appie that uses this picture as a homescreen:

I might be able to recreate the layout with a TableLayout, but this will be difficult to get it perfectly aligned with the buttons in the image. The default layout options make it very difficult, or maybe impossible, to allow for selection of the buttons on the image (especially when the buttons are in an arc-path). Can anyone tell me how this is done?

View Replies!   View Related
Android :: Adding A Custom ImageView To Main Layout
I was looking over this code about extending an ImageView:

And i was wondering how can i add the new View to an existing xml layout file, along with some other views.

Already i did this inside my main linear layout:


But the problem is that this way the onDraw method doesn't get called.

Maybe some examples where you combine CustomViews with xml layout.

View Replies!   View Related
Android :: Emulator Force Closes When Loading Custom Layout
i created a custom layout where i have a couple of LinearLayout in a ScrollView. Problem is when i set my SetContentView to my custom Layout (when the application starts), the emulator gives an error and force closes! i don't know why. i have tried with another custom layout or set it to main and it seems to work fine.

View Replies!   View Related
Android :: Alert Dialog With Custom Layout Failing / Get This To Display?
So this is related to a question I asked earlier. I am trying to display an alert using a specified layout. My layout is:

And the code to call and show the alert dialog is..

When I run it I get an error saying:

Uncaught handler: thread main exiting due to uncaught exception
android.view.WindowManager$NadTokenException: Unable to add window -- token null is not for an application

I've looked through the android development site and can't figure it out. I think I'm just missing something obvious but the fix isn't jumping out at me. How can I get this alert dialog to display?

View Replies!   View Related
Android :: OnClick() Event On An Item Of ListView Custom Row Layout
I have a ListView whose rows are formatted by me. Each row has a mix of ImageView and TextView. I have also implemented my own adapter and am able to draw each row through it.

Now, I would want something like this-

User clicks on an ImageView (not anywhere else on the row, but only this ImageView should respond to clicks)
I get to know the position of the row whose ImageView was clicked.

I have tried many things for this and have wanted my code to be as efficient as possible (in terms of overkill).
Currently i can capture the click event on that particular ImageView only, but I can't know which row was clicked.

I have provided an attribute in the Row XML like this-


And in my code, I have a method like this:


I can get the parent row (perhaps) but am not sure how to go further from here.

View Replies!   View Related
Android :: ListView With RadioButton In SingleChoice Mode And A Custom Row Layout
I have a ListView, which is in singleChoice mode. All I want is to display a RadioButton to the side, that when clicked highlights to say it is selected, and when a different one is clicked that one goes back to unselected and the new one becomes selected. Why is this so hard? This should not be this complicated. I've spent DAYS looking for an appropriate answer to this and I have found nothing, so I'm asking hopefully in a clear and concise manner.

My layout for the listview (R.layout.view_orders):


My custom row (R.layout.orders_row):


My onCreate() method:


Now everything underlying works as expected, you click on a radiobutton and through it's tag I can appropriately select that item from the list and manipulate it how I want. However, when the first radio button is clicked, the last one will be selected. Click that same radio button again, and it is now selected as well. Click it once more and nothing happens, both the last and the first are selected. Now I click any other one on the list, it gets selected like expected. Click anyone of the selected radio buttons and nothing happens, the radio button remains selected.

I have tried using the following in onCreate():


And that just shows no radio buttons at all. AWESOME.

Now maybe (read: most likely), I'm just dense and can't figure this out, but I've seen this question asked a lot with no real answer. Lots of references to other tutorials or to the Commonsware guy's book. However, the comments are old now and his repository has changed so much, that those are no longer correct answers.

So, does anyone have any idea how to get the expected functionality out of this? Or failing that, just pass me along the GMail app's source code.

View Replies!   View Related
Android :: Multiple Custom View (Derived From Relative Layout) In One Line
I have created a custom view by extending Relative Layout and it looks like this: The layout for the view:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="">
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center_horizontal">
<ImageView android:id="@+id/type_picture_preview"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/type_picture_noimage" android:layout_alignParentRight="true"
android:paddingTop="15dip" android:paddingRight="15dip" />
<ImageView android:id="@+id/type_picture_delete"
android:layout_alignParentRight="true" />

I am struggling to get two or more layouts on a single line.

View Replies!   View Related
Android :: Class Cast Exception When Inflating A Custom Relative Layout
I get this exception when I try to inflate

07-22 19:15:39.903: ERROR/AndroidRuntime(3810): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout

I have a base class:

public class UIBase extends RelativeLayout {}

And a more specific class:

public class Countdown extends UIBase {}

Then I try to inflate and it exceptions:

UIBase newView = (UIBase) inflater.inflate(layoutId, parent, true);

Here's the XML file:


View Replies!   View Related
Android :: Custom BaseAdapter - Dynamic Updates - Crash In ListView Layout
I'm trying to get my first Android app stable enough for the marketplace, and I've hit a brick wall with one exception that I don't understand. Probably I'm doing something stupid, but I can't tell what, and after several hours googling and experimenting, I thought I'd see if I can get some help. My Activity extends ListActivity, and the parts I think are most important are extracted below:

GroupedListAdapter is a simple class that extends BasedAdapter to provide headings for sections of the list (not unlike the Fancy ListView tutorials that are floating around).

I create this in onCreate, and it works fine. Inside onListItemClick, I do some actions which will create a different set of list contents. I "clear" the adapter, which empties the contents, and call reload, which repopulates it. Then I call notifyDataSetChanged.

Most often, this seems to work, but also fairly often, I get the exception following the code snippets below - this seems to indicate the ListView is not in sync with my changes. Lately this crash happens 100% of the time under the simulator.


View Replies!   View Related
Android :: Cannot Display Image Correctly Using Custom Item Layout In ListView
I am using a ListView to display my custom item layout, which may contain some TextViews and an ImageView.

This is the item layout I made (post_item.xml):


I don't put the ImageView initially in the xml layout, but I will insert it when I need to the FrameLayout programmatically (I also put another views in it when needed). So, there will be some items which has ImageView in it and which don't.

I get the image to fill the ImageView from the Internet (through URL), decode it as Bitmap, and keep it as a Bitmap variable in a class represents the custom item layout (class PostItem).

When the activity shows for the first time it looks fine, but as I scrolled through the items then a problem showed up, the items which shouldn't show any image show the image from the other item which should, although they don't have any ImageView (because I didn't insert it).

I am using SDK 1.6 and the emulator. Haven't tried it in real device because I don't have it.

Here is my code for the Adapter:


And this is the code to prepare the items:


Is this the bug in the emulator or there is some mistake in my code (probably memory problem for the Bitmap)?

View Replies!   View Related
Android :: Relative Layout In Java Code With Inflate And Custom View - Position Error
I have a custom view that I had to write for a large scrollable image, as the images are larger than the size of the screen. Before, I had tried to do it by putting the image into a ScrollView but that of course didn't work. The view itself is within a RelativeLayout within the activity and at the bottom of the screen I have two buttons that are used for navigation and at the top a TextView with a caption for the activity (the main header is already being used here for instruction). In my below code, I've checked the Hierachy Viewer to confirm all the elements are loaded and in the Activity I can see the TextView, however it overlays the ZN5ScrollView area and below the image I just have a blank area of the size defined rather than my buttons. For the bottom navigation, the Hierachy Viewer is saying the absolute_y of the bottom navigation is 480. I'm wondering if anyone can help with my layout code here to get this working correctly? Bottom navigation is 50px high, ZN5ScrollView is 365px above the navigation, and the TextView takes up the rest of the area at the top

View Replies!   View Related
Android :: Custom View Extending View-Class / Still Based On XML-Layout
I want to build my own custom view which should look like the Crysis-GUI.At first I designed a XML-based Layout and made it visible via the setContentView(int resid)-Method. Worked pretty well.But now I wan't to go a step further and draw in my Layout. So I created a new Class, let it extend View and overrode the onDraw()-Method. So far so good.But how can I still use my XML-Layout? I can't do setContentView anymore, so how could the same effect be achieved?

View Replies!   View Related
Android :: Phone "hover" Event In Custom Layout
I have a custom layout that I have written that basically just displays a bunch of Image Views. I am handing on Touch events for all the Image Views in my layout. However, if a user touches one image View and then drags over another Image View, I would like to be able to handle that as well. How would I go about capturing this behavior?

View Replies!   View Related
Android :: Space Between Component
I am putting one spinner and one button using following code. Can some one tell me how can i put some space between it?

View Replies!   View Related
Android :: Use Of Service Component?
Service Component is used to do some task which can be done without user interaction. But for that we have to run a thread in subclass of the Service. I think we can create a thread in Activity class itself then what is the use of Service component? Why don't we create another thread and write the non interacting code in this thread.

View Replies!   View Related
Copyright 2005-08, All rights reserved