The difference between removeViewInLayout() and removeAllViews()

by xhy » Mon, 24 May 2010 11:00:36 GMT


Sponsored Links
 hi all ,i inflate a xml nd add it to a mapview .But i want to remove it
when  i click a button.I must click the button two times sothat i can remove
it when i  use the  removeViewInLayout()  method ,but if
using removeAllViews() will do . Why?Thank you !


the code is:
add the view to mapview:

                 ll = (LinearLayout)mInflater.inflate(R.layout.bubble,null
);
         LayoutParams lp = new
LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, p, 0, -70,
 LayoutParams.MODE_MAP | LayoutParams.CENTER);

         map.addView(ll,lp);


remove it:
            map.removeAllViews();     ////////ok
            map.removeViewInLayout(ll); ///////must click two times

-- 
xhy

--



Other Threads

1. listview activity not stopping

i have face this error,i cant found the solution please
help.Application is based on listview Activity.when u click on one
listview item then it ll go to another listview.second activity start
but ther is some error please help yr...this error ......
--------------------------------------------------------------------------------------------------------------------------------------------------------------------


07-27 15:38:48.117: WARN/dalvikvm(741): threadid=3: thread exiting
with uncaught exception (group=0x4000fe70)
07-27 15:38:48.127: ERROR/AndroidRuntime(741): Uncaught handler:
thread main exiting due to uncaught exception
07-27 15:38:48.147: ERROR/AndroidRuntime(741):
java.lang.RuntimeException: Unable to stop activity
{com.vigyaapan.Exercise/com.vigyaapan.Exercise.GymExercise}:
java.lang.NullPointerException
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread.performStopActivityInner
(ActivityThread.java:2905)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread.handleStopActivity(ActivityThread.java:
2948)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread.access$2100(ActivityThread.java:112)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1708)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.os.Looper.loop(Looper.java:123)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
dalvik.system.NativeStart.main(Native Method)
07-27 15:38:48.147: ERROR/AndroidRuntime(741): Caused by:
java.lang.NullPointerException
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.Activity.performStop(Activity.java:3575)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     at
android.app.ActivityThread.performStopActivityInner
(ActivityThread.java:2902)
07-27 15:38:48.147: ERROR/AndroidRuntime(741):     ... 11 more

------------------------------------------------------------------------------------------------------------------------------------------------




here is my program
-------------------------------------------
package com.vigyaapan.Exercise;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.AndroidRuntimeException;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class GymExercise extends ListActivity
{
        DBExercise dbExercise = new DBExercise(this);
        Cursor cursor;
        String aryListMainMenu[];
        int intGetSelectedItem = 0;
        protected ListView lv;

    public void onCreate(Bundle savedInstanceState)
    {
        try
        {
                super.onCreate(savedInstanceState);

                dbExercise.openDataBase();
                dbExercise.getTricepDipImage();
                aryListMainMenu = dbExercise.displayMainMenu();
                startManagingCursor(cursor);
            if(dbExercise != null)
                        dbExercise.close();

            setContentView(R.layout.main);
            lv = (ListView)this.findViewById(android.R.id.list);
            setupListView();
        }
        catch(NullPointerException e)
        {
                e.printStackTrace();
        }
    }

    private void setupListView()
    {
        try
        {
                ArrayAdapter listItemAdapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1,aryListMainMenu);
                    lv.setAdapter(listItemAdapter);
                }
        catch(AndroidRuntimeException e)
        {
                e.printStackTrace();
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position,
long id)
    {
        try
        {
                super.onListItemClick(l, v, position, id);
                if(position == 0)
                {
                        Intent intentShoulder = new Intent
(GymExercise.this,ShoulderViewController.class);
                        startActivity(intentShoulder);
                        lv.bringToFront();



                }
                if(position == 1)
                {
                        Intent intentTriceps = new Intent
(GymExercise.this,TricepsViewController.class);
                        startActivity(intentTriceps);


                }
                if(position == 2)
                {
                        Intent intentBiceps = new Intent
(GymExercise.this,BicepsViewController.class);
                        startActivity(intentBiceps);


                }
                if(position == 3)
                {
                        Intent intentChest = new Intent
(GymExercise.this,ChestViewController.class);
                        startActivity(intentChest);


                }
                if(position == 4)
                {
                        Intent intentBackView = new Intent
(GymExercise.this,BackViewController.class);
                        startActivity(intentBackView);

                        }
                if(position == 5)
                {
                        Intent intentLeg = new Intent
(GymExercise.this,LegViewController.class);
                        startActivity(intentLeg);


                }
            }
        catch(AndroidRuntimeException e)
        {
                e.printStackTrace();
        }
    }




}
---------------------------------------------------------------------------------------------------------------







package com.vigyaapan.Exercise;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TricepsViewController extends ListActivity
{
        DBExercise dbExercise = new DBExercise(this);
        protected ListView lv;
        String[] aryTricepsList;
        public void onCreate(Bundle savedInstanceState)
        {
                try
        {
                super.onCreate(savedInstanceState);
                System.out.println("Inside Triceps class");
                dbExercise.openDataBase();
                aryTricepsList = dbExercise.getTriceps();
                if(dbExercise != null)
                        dbExercise.close();

                setContentView(R.layout.triceps);
            lv = (ListView)this.findViewById(android.R.id.list);
            setTricepsList();

        }
                catch(RuntimeException e)
                {
                        e.printStackTrace();
                }
        }

        /*
         * This method will get the populated values from database an load
into list view of triceps list
         */
        public void setTricepsList()
        {
                try
                {
                        ArrayAdapter listItemAdapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1,aryTricepsList);
                        System.out.println("Array 
count===>"+listItemAdapter.getCount());
                        lv.setAdapter(listItemAdapter);
                }
                catch(RuntimeException e)
                {
                        e.printStackTrace();
                }
        }
}




--~--~---------~--~----~------------~-------~--~----~

2. How did they made those "solve the math to dismiss the Alarm Clock" type apps?

I certainly hope they don't hold a wake lock. :)  They should just schedule
an alarm.








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

3. Threads for networking and DatagramSocket

4. pthread lib problem

5. where to download the linux-kernel for Android 1.5?

6. How to catch event from the virtual keyboard ?

7. how to disable the keygaurd and screen locking in android