How to make data independent of activity

by rajaramyadhav » Sat, 17 Jul 2010 02:25:35 GMT


Sponsored Links
 Hi All,

I am new to  Android development. My requirement is something like
this. I have two list activities and a service. I also have to
maintain some data in an two different arraylist which are used by the
activity to display. The data will be populated by the service. Since
adding the new elements to arraylist has to be done by the service,
the data has to be independent of the activity. So I had to put it in
an external class. Now whenever an element is added the activity
should be notified. How can I do this in a clean way? I somehow made
it to work using a static handler for activity and a static adapter .
But I dont think this is a good way to do this.  Can someone suggest
me a better way?

Any sample code snippets would help too..

Thanks in advance for your help.
Raja Ram

--



Other Threads

1. ListView doesn't react to some clicks

Hi! I'm having troubles with the ListViews. It's impossible to me make
them work correctly. Each row contains two buttons, a checkbox, an
ImageView and a TextView. I want a row expands (show the buttons and
the checkbutton) when I make a long click and perform an action with
normal clicks. I tried to use the setItemsCanFocus(true) method but
the row ignores the clicks. Only if I long press the TextView I get
the row expands, but then it's impossible to make the row contracts
long clicking another time on the TextView. Depends the textview
configuration (if I use the deprecated singleLine="true" or lines="1"
properties instead of android:inputType="text") the behaviour changes,
the row reacts fine (the row expands or contracts) to all the clicks
but only on the TextView. I want that if the user clicks on the row
itself, it expands but it seems that only the TextView pass the clicks
events to the row.

Apart from that, I'm not able to implement correctly the
alignWithParentIfMissing property following the "Android Layout Tricks
#1" page of Romain Guy. I want that if the buttons and the checkbox
are hidden (visibility="gone"), the TextView take up all the space and
it's centered on the layout. When those elements get visible, oddly
the TextView desappears and if they are not visible, the TextView
doesn't appears at the center of the layout.

Here is all the XML code about the listview and the items (if you need
the adapter's code or something else, tell me, but I think the problem
is in the XML):

This is the XML code of the ListView:
<ListView android:id="@+id/login_list_view"
                android:layout_below="@id/login_text"
                android:layout_above="@id/login_another_button"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="3dip"
                android:divider="#EDEFF4"
                android:cacheColorHint="#EDEFF4"
                android:dividerHeight="3dip"
                android:scrollbars="none"/>

And this is XML code of the list items:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="6dip"
        android:paddingBottom="0dip"
        android:background="@drawable/login_list_item_background">
        <ImageView
                android:id="@+id/user_image"
                android:layout_width="50dip"
                android:layout_height="50dip"
                android:layout_alignParentTop="true"
                android:layout_marginRight="6dip"
                android:src="@drawable/icon"
                android:scaleType="fitXY"/>
        <CheckBox
                android:id="@+id/login_list_item_access_always"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_toRightOf="@id/user_image"
                android:layout_alignParentRight="true"
                android:text="@string/login_list_item_access_always"
                android:textColor="#83021837"
                android:textSize="15sp"
                android:paddingLeft="45dip"
                android:visibility="gone"/>
        <TextView
                android:id="@+id/user_name"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@id/login_list_item_access_always"
                android:layout_toRightOf="@id/user_image"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:layout_alignWithParentIfMissing="true"
                android:inputType="text"
                android:textColor="#FF6D84B4"
                android:textSize="18sp"
                android:gravity="center_vertical"/>
        <Button
                android:id="@+id/login_list_item_login"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_below="@id/login_list_item_access_always"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:text="@string/login_list_item_login"
                android:textColor="#FF000000"
                android:visibility="gone"/>
        <Button
                android:id="@+id/login_list_item_delete"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_below="@id/login_list_item_access_always"
                android:layout_toLeftOf="@id/login_list_item_login"
                android:layout_alignParentBottom="true"
                android:text="@string/login_list_item_delete"
                android:textColor="#FF000000"
                android:visibility="gone"/>
</RelativeLayout>

Thank you.

-- 

2. Collecting my Market installation statistics

On the Market web page, I can see how many copies of my apps have been
installed.

But, this only shows the current total. If I want to see historical
trends, I need to check the page daily and record the numbers myself
-- an annoyance at best.

Is this info available anywhere on the Market site?
If not, has anyone written a screen-scraping utility (or equivalent)
that can harvest the data into a spreadsheet?

Thanks,
David

-- 

3. Arabic Text to Display

4. SDIO on android

5. ram_console driver and /proc/last_kmsg

6. Trackball / d-pad navigation and Tabbed activities

7. onSurfaceCreated called twice