Is there an easy way to save a whole viewgroup with its data together? For example if initially i have this view and during the app run some of the view's background image changes, some views become invisible, or its' text changes, etc. How can I save the state of the view, in case user quits app?
<RelativeLayout android:layout_width="wrap_content" android:id="#+id/water_room_common"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- storage layout -->
<View android:id="#+id/gap" android:layout_width="wrap_content"
android:layout_height="0dip" android:layout_alignParentBottom="true" />
<RelativeLayout android:id="#+id/storage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_above="#id/gap" android:layout_marginBottom="10dp"
android:layout_marginRight="27dp" android:layout_marginLeft="10dp"
android:layout_toLeftOf="#id/bag" android:orientation="horizontal"
>
<ImageButton android:id="#+id/ImageButton02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton01"
android:background="#drawable/single_square" android:onClick="itemSelected" />
<ImageButton android:id="#+id/ImageButton03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_centerHorizontal="true" android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/ImageButton02" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton03"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton05"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton04"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton06"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton05"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
</RelativeLayout>
<ImageButton android:id="#+id/bag" android:layout_width="65dp"
android:layout_height="65dp" android:layout_alignBottom="#+id/storage"
android:layout_alignParentRight="true" android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:onClick="bagClicked"/>
<ImageButton android:id="#+id/left" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="#+id/storage"
android:layout_centerVertical="true" android:background="#null"
android:onClick="previousWall" android:src="#drawable/left" />
<ImageButton android:id="#+id/right" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignRight="#id/bag"
android:layout_centerVertical="true" android:background="#null"
android:onClick="nextWall" android:src="#drawable/right" />
</RelativeLayout>
See this answer. You need to override onSaveInstanceState for transient changes or override onPause and onResume for permanent changes.
Read the API guide here
Update
This is a summary of this training
Picture this scenario. You have a notepad app. On the homescreen, the user has a list of recently created notes (NoteList Activity) and the user can choose to create a new note or edit an existing note and changes will be stored in a database.
When the user clicks on an item brings another activity (NoteEditActivity) to the foreground. If the user is in the process of editting a note and the NoteEditActivity loses focus for some reason (e.g a call comes in or the user just decides to switch to another app without clicking the "confirm button") the NoteEditActivity goes from being focused to being paused and then shortly after it is stopped.
To prevent the user from loosing the current edit, you need to call onPause where you would want to save any changes to the database. Now if the app is in the stopped (onStop) and the user returns to the edit it will not go through onCreate but rather through onResume which is where you want to "resume" from where the user left.
This picture should further explain.
Notice how onResume gets called every time the activity is about to be focused and not onCreate.
You can follow the training above for better understanding.
Related
i have a problem with my app: i'm using crashlytics by Fabric, (my app is pubblishes in the play store) to have log of possible crash, and i have this error ".. MainActivity: android.content.res.Resource$NotFoundException:Resource ID#0x7f09001b"
(Crashlytics say to me that the device is a samsung galaxy s4 with Android 5.1 and root )
CrashLytics screen
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main); <---- LINE 102 THAT GIVE
THE ERROR , ACCORDING TO
CRASHLYTICS
ping = (ImageButton)findViewById(R.id.ping);
internet =(TextView)findViewById(R.id.Internet);
banda5Ghz =(TextView)findViewById(R.id.BandeSupp);
SpeedNet =(TextView)findViewById(R.id.VR);
ipv6 =(TextView)findViewById(R.id.showIPv6);
txVsegnale =(TextView)findViewById(R.id.intensità);
aggiorna = (ImageButton)findViewById(R.id.Aggiorna);
share = (ImageButton)findViewById(R.id.sharebtn);
clipboard = (ImageButton)findViewById(R.id.clipboard);
rating = (ImageButton)findViewById(R.id.ratebtn);
IP =(TextView)findViewById(R.id.IP);
showIPv4 =(TextView)findViewById(R.id.showIPv4);
// TextViewWifi =(TextView)findViewById(R.id.TextViewWifi);
TextViewwifi_info = (TextView)findViewById(R.id.wifi_info);
MacA = (TextView)findViewById(R.id.MacAdd);
//switch gestione notifiche
notifiche = (Switch)findViewById(R.id.switchNot);`
......
The same device crash 2 times in a short time, with same error.
My app is an app that show infos on your wifi connection, such as IP, network velocity, etc etc, also have system notification and widgets and a service that run in background .
I have also done different layout for different devices with different screen size and different screen dpi
My Layouts
No other logs from other device with same problem .I want to know if is a specific problem of this device ( may be related to root access given to this device ) or is a problem of my application.
Not sure if it is linked to this, but, i was tryeing to add split screen function to my app, and , adding android:resizeableActivity="true" to manifest, make app crash in the same code line, so, i solve by settings to false and not include split screen feature in my app.
I CONFIRMED THAT TRIEING TO USE SPLIT SCREEN GIVE ME THE SAME ERROR, SAME RESOURCE NOT FOUND EXCEPTION, how can i see which resource have this id ?
android.content.res.Resources$NotFoundException: Resource ID #0x7f09001b
THE APP Crash only in this case , no other crash, do i have to define a minimum width and weight to use split Screen ?
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ShowMyIp.utente.ShowMyIp.MainActivity">
<TextView
android:id="#+id/Internet"
android:layout_width="match_parent"
android:layout_height="225dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/roundcorner"
android:layout_marginTop="8dp"
android:paddingTop="27dp"
android:textColor="#646464"
android:textSize="13sp"
android:layout_marginLeft="7dp"
android:layout_marginRight="8dp"
android:textStyle="italic" />
<TextView
android:id="#+id/Internet2"
android:layout_width="match_parent"
android:layout_height="195dp"
android:layout_alignEnd="#+id/internet4"
android:layout_below="#+id/internet4"
android:layout_marginTop="14dp"
android:layout_marginLeft="7dp"
android:background="#drawable/roundcorner" />
<TextView
android:id="#+id/internet4"
android:layout_width="match_parent"
android:layout_height="195dp"
android:layout_alignStart="#+id/Internet"
android:layout_below="#+id/Internet"
android:layout_marginRight="8dp"
android:layout_marginTop="17dp"
android:background="#drawable/roundcorner"
android:textSize="13sp" />
<TextView
android:id="#+id/MacAdd"
android:layout_width="275dp"
android:layout_height="35dp"
android:layout_alignStart="#+id/txtMac"
android:layout_below="#+id/BandeSupp"
android:layout_marginTop="35dp"
android:textAlignment="viewStart"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/IP"
android:layout_width="150dp"
android:layout_height="45dp"
android:layout_alignBaseline="#+id/Internet"
android:layout_alignBottom="#+id/Internet"
android:layout_alignStart="#+id/internet4"
android:layout_marginStart="45dp"
android:text="IP Address"
android:textColor="#E1E140"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="#+id/showIPv4"
android:layout_width="230dp"
android:layout_height="45dp"
android:layout_alignStart="#+id/IP"
android:layout_below="#+id/intensità"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/wifi_info"
android:layout_width="220dp"
android:layout_height="55dp"
android:layout_alignStart="#+id/showIPv4"
android:layout_below="#+id/showIPv4"
android:text="Non Connesso"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/velocita"
android:layout_width="155dp"
android:layout_height="45dp"
android:layout_above="#+id/VR"
android:layout_alignEnd="#+id/txvIPV6"
android:text="Velocità rete"
android:textColor="#E1E140"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="#+id/VR"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/wifi_info"
android:layout_alignEnd="#+id/velocita"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="italic" />
<ImageButton
android:id="#+id/Aggiorna"
android:layout_width="200dp"
android:layout_height="75dp"
android:layout_alignEnd="#+id/intensità"
android:layout_alignTop="#+id/Internet2"
android:layout_marginEnd="21dp"
android:layout_marginTop="56dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:textColor="#android:color/white"
app:srcCompat="#drawable/btn_aggiorna" />
<TextView
android:id="#+id/intensità"
android:layout_width="190dp"
android:layout_height="65dp"
android:layout_alignEnd="#+id/Internet"
android:layout_alignTop="#+id/IP"
android:layout_marginEnd="21dp"
android:textColor="#android:color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/txtMac"
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_alignStart="#+id/showIPv4"
android:layout_alignTop="#+id/internet4"
android:layout_marginTop="28dp"
android:text="MAC Address"
android:textColor="#E1E140"
android:textSize="18sp" />
<Switch
android:id="#+id/switchNot"
android:layout_width="145dp"
android:layout_height="85dp"
android:layout_alignStart="#+id/MacAdd"
android:layout_alignTop="#+id/Aggiorna"
android:layout_marginStart="28dp"
android:textColor="#E1E140"
android:textSize="18sp"
tools:text="Notifiche" />
<TextView
android:id="#+id/txvIPV6"
android:layout_width="75dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/txtMac"
android:layout_alignEnd="#+id/Aggiorna"
android:text="IPV6"
android:textColor="#E1E140"
android:textSize="18sp" />
<TextView
android:id="#+id/showIPv6"
android:layout_width="220dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/MacAdd"
android:layout_alignStart="#+id/Aggiorna"
android:textAlignment="viewStart"
android:textColor="#android:color/black"
android:textSize="17sp" />
<ImageButton
android:id="#+id/ratebtn"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignEnd="#+id/Internet2"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:layout_marginEnd="10dp"
android:background="#android:color/transparent"
app:srcCompat="#drawable/rating_button"
android:scaleType="fitCenter"
/>
<ImageButton
android:id="#+id/sharebtn"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/ratebtn"
android:layout_marginEnd="23dp"
android:layout_toStartOf="#+id/ratebtn"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:srcCompat="#drawable/share_button" />
<ImageButton
android:id="#+id/clipboard"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/sharebtn"
android:layout_toStartOf="#+id/VR"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:srcCompat="#drawable/clipboard" />
<TextView
android:id="#+id/BandeSupp"
android:layout_width="130dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/txvIPV6"
android:layout_toEndOf="#+id/showIPv4"
android:textColor="#android:color/black"
android:visibility="invisible"
android:textSize="17sp" />
<ImageButton
android:id="#+id/ping"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignBottom="#+id/clipboard"
android:layout_alignEnd="#+id/switchNot"
android:background="#android:color/transparent"
android:visibility="invisible"
app:srcCompat="#drawable/ping" />
</RelativeLayout>`
here is my layout (large-port-mdpi)
App still crash entering in split screen mode, with "no found exception ..." ; i've made another simple app , following Android developer guide to make multiview support, and this app work, no problem when entering in split screen, , i only added to the Manifest same code i wrote for this app " android:resizeableActivity="true"". Anyone know about to resolve this error? why my app, dosen't find layout resource entering in split screen mode??
Check your MainActivity Layout Xml in Text Format, There Has to be Line with a Yellow Warning on it, Or a Red Line.
Check the Layout Xml, And Then,
Check If You Missed Something Like LinearLayout Being RelativeLayout and you Declared it with this mistake.
Then Check If You've Used Anything like below:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myRelativeLayout.getLayoutParams();
LinearLayout.LayoutParams Param1 = (LinearLayout.LayoutParams) myLinearLayout.getLayoutParams();
If Yes, Reply me and I'll tell you what to do.
This is a code when user choose one image and will run this coding (finish()), if choose wrong image then do not run the finish() .
but i dont know how to make the image as a value , how i select the drawable a or b or c and link to this function
if(eyeDected)
{
if(detectedFrame > 25)
{
eyeDected = false;
detectedFrame = 0;
finish();
} else {
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
} else {
eyeDected = true;
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
I want to ask about how to store the drawble/image into value?
i'm developing a lock screen application , when user choose the correct image will execute the unlock function
This is a layout showing 3 images and give user choose one images inside a lock screen.
In the setting , i'll let user to choose one image as the correct image that will execute the code
set_image.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/new_build_resize_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/setting">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Image "
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="38dp"
android:textColor="#color/abc_primary_text_material_light" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select one graphical passcode as your lock screen."
android:id="#+id/textView2"
android:textSize="22dp"
android:textColor="#1547bb"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="135dp"
android:layout_height="140dp"
android:src="#drawable/a"
android:id="#+id/imageButton1"
android:layout_above="#+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2" />
<ImageButton
android:layout_width="126dp"
android:layout_height="126dp"
android:src="#drawable/b"
android:id="#+id/imageView2"
android:layout_above="#+id/imageView3"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="126dp"
android:layout_height="126dp"
android:src="#drawable/c"
android:id="#+id/imageView3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="46dp" />
</RelativeLayout>
Here is what I am trying to do. I am creating a drag and drop controller. Users are able to move the controls where they want on the screen to save it. I have everything else done, except this. I have thought of a couple different ideas to get this to work, but most of them do not work so well with the drag and drop feature.
I have created an XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="50dp"
android:layout_height="40dp"
android:text=""
android:id="#+id/dpad_up"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:visibility="invisible"/>
<Button
android:layout_width="50dp"
android:layout_height="40dp"
android:text=""
android:id="#+id/dpad_down"
android:layout_below="#+id/dpad_up"
android:layout_centerHorizontal="true"
android:visibility="invisible"/>
<Button
android:layout_width="50dp"
android:layout_height="40dp"
android:text=""
android:id="#+id/dpad_left"
android:layout_alignTop="#+id/dpad_right"
android:layout_toStartOf="#+id/dpad_up"
android:visibility="invisible"/>
<Button
android:layout_width="50dp"
android:layout_height="40dp"
android:text=""
android:id="#+id/dpad_right"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/dpad_up"
android:layout_marginTop="22dp"
android:visibility="invisible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/d_pad"
android:background="#drawable/d_pad"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/dpad_down"
android:layout_alignStart="#+id/dpad_left"
android:layout_alignEnd="#+id/dpad_right" />
</RelativeLayout>
I was thinking of using that XML bring into my activity and do a drag and drop, but I am not sure how I could do that. Any ideas or help would be great. I just need to be able to perform a drag and drop and have each of the directions buttons register when pressed to perform the action.
Invisible views are not touchable.
Just change Button into View or Space, and let it visible.
I do not understand why this layoutcan not be selected anything in android tv.
it's not possible select any button or whiget, or insert text.
Please help me, and if you can and tell the reason.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp" />
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:src="#android:drawable/ic_menu_share"
app:elevation="6dp"
app:borderWidth="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
Firstly, you have to keep focus of any one of items (i.e. Button, TextView, etc.) as below. And also, you have to apply it's nextFocusDown, nextFocusLeft, nextFocusRight & nextFocusUp properties. So it will fire it's releveant event when you click TV remote navigation buttons.
Add request focus to your edit text like this,
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bTextUrl"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#faf6f6"
android:layout_marginTop="60dp"
android:nextFocusDown="#+id/bSendUrl">
<requestFocus></requestFocus>
</EditText>
<Button
android:layout_width="#dimen/latimea_button_send_tv"
android:layout_height="#dimen/inaltimea_button_send_tv"
android:text="#string/button_send_android_tv"
android:id="#+id/bSendUrl"
android:background="#drawable/button_send_tv"
android:layout_below="#+id/bTextUrl"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
</Button>
And after that, you can add more properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus next item.
I am using a Relative Layout(RL) to Hold a List View(lv) and a few bunch of other widgets like Text View(tv), Edit Text(et), then a few Buttons(btn) and finally one Progress Bar(pb).
Scenarios
1. When i add child Views to the Parent Container View viz. Relative Layout(rl), in the order: RL(Btn1->Btn2->tv1->tv2->LV->pb). Then we have no problem, i mean No Exception, No Problem.
2. But when i do the ordering change like RL(tv1->tv2->LV->Btn1->Btn2->pb). then i am getting a classcast Exception.
Note: the two buttons should be over the listview, as both of them are social website buttons, i mean Facebook and Twitter.
XML Code:
<RelativeLayout
android:id="#+id/rlfornews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:background="#drawable/newsbg"
android:orientation="vertical"
android:paddingBottom="5dip" >
<Button
android:id="#+id/btnbasetw"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="10dip"
android:background="#drawable/twitter_icon"
android:visibility="gone" />
<Button
android:id="#+id/btnbasefb"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_toLeftOf="#id/btnbasetw"
android:background="#drawable/facebook_icon"
android:visibility="gone" />
<TextView
android:id="#+id/tvnewscon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:background="#drawable/newstitle"
android:gravity="center_vertical"
android:paddingLeft="8dip"
android:shadowColor="#color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:text="#string/news"
android:textColor="#color/white" />
<TextView
android:id="#+id/tvfornews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvnewscon"
android:layout_marginTop="10dip"
android:gravity="center"
android:text="#string/no_data_found"
android:visibility="gone" />
<ListView
android:id="#+id/lvdashboardnews"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tvnewscon"
android:padding="4dip"
android:visibility="visible" >
</ListView>
<ProgressBar
android:id="#+id/pbfornews"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
Note: The Progress Bar might be below, but it is just to user information, that some data is loading. and when i get that data, i am making its Visibility to VIEW.GONE state, and the List View being already there !
My question is when i follow the First Scenario, even though i have a Progress Bar from the entire time, i am not getting a Class Cast Exception. But i am getting the exception, when i change to Scenario 2. So why i am i getting it?
I am not sure about these but may be the reason is you have used the android:layout_below = "#id/textview" instead of use these android:layout_below = "#+id/textview" all UI.
If you can do these UI using the LinearLayout.