I want to inflate an xml file into MainActivity - java

I have an xml file named " Editt.xml ",I want to inflate #+id/myEditText into MainActivity every time I click an Button from the activty_main named " #+id/Button01 "
" Editt.xml " is this :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/myEditText"
android:layout_weight="1" /> </LinearLayout>
and " activity_main "
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Button01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<ScrollView
android:layout_below="#id/Button01"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/tableRow">
<LinearLayout
android:id="#+id/gamehistory"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>

View v = getInflater().inflate(Editt.xml,null);
LinearLayout linearLayout = (LinearLayout) findViewById(R.layout.game_layout);
linearLayout.addView(v);

Related

Android: Order of addition of fragments

I have this code:
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener()
{
//Se aggiungo un fragment A al container X e aggiungo il fragment B allo stesso container, il fragment B andrĂ  sopra
//il fragment A
#Override
public void onClick(View v)
{
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if(ko==0)
{
MyFragment fragment = MyFragment.createFragment(0);
fragmentTransaction.add(R.id.formazione3,fragment);
ko++;
}
else if(ko==1)
{
MyFragment fragment = MyFragment.createFragment(1);
fragmentTransaction.add(R.id.formazione2,fragment);
ko++;
}
else if(ko==2)
{
MyFragment fragment = MyFragment.createFragment(2);
fragmentTransaction.add(R.id.moduli2,fragment);
ko++;
}
else if(ko==3)
{
MyFragment fragment = MyFragment.createFragment(1);
fragmentTransaction.add(R.id.moduli5,fragment);
}
fragmentTransaction.commit();
}
});
Well, I'm experiencing the order of addition of fragments. I have 4 fragments and I don't understand why some fragments, when I add them, go under the bigger fragment, while other ones go on the bigger fragment in their container.
formazione3>formazione2 (formazione2 is contained in formazione3)
moduli2>moduli5 (moduli5 is contained in moduli2, moduli2 is contained in part in formazione3)
When I add the second fragment, it doesn't show, I think that it goes under the previous fragment, so it goes under the bigger. When I add the third fragment, it goes in part under the first fragment, the first is bigger. When I add the fourth fragment, it goes on the third, but the third is bigger than the fourth and above all the the fourth is contained in the third. How does it work? I don't understand at all!
This is the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.utente.fantacalcio.FormazioniActivity"
android:weightSum="1"
android:id="#+id/activity_formazioni_layout">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:id="#+id/button2" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/button" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="107dp"
android:layout_height="match_parent"
android:id="#+id/moduli">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="92dp"
android:layout_height="match_parent"
android:id="#+id/moduli1">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione1">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="71dp"
android:layout_height="match_parent"
android:id="#+id/moduli2">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione2">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="51dp"
android:layout_height="match_parent"
android:id="#+id/moduli3">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione3">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="29dp"
android:layout_height="match_parent"
android:id="#+id/moduli4">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione4">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="11dp"
android:layout_height="match_parent"
android:id="#+id/moduli5">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione5">
</RelativeLayout>
</LinearLayout>
Your parent layout is a RelativeLayout , the default behavior for this layout is that first child view is under the last child view.
In your xml this child :
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="51dp"
android:layout_height="match_parent"
android:id="#+id/moduli3">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione3">
</RelativeLayout>
</LinearLayout>
is under this child view :
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="71dp"
android:layout_height="match_parent"
android:id="#+id/moduli2">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione2">
</RelativeLayout>
</LinearLayout>
so when the views are inflating , this is the opposite formazione3 is over formazione2.
Moreover your LinearLayout have these attributes :
android:layout_width="match_parent"
android:layout_height="match_parent"
so they take all the place available.
Try to set fixe size in dp instead of match_parent to see what's really happen.
Hope this helps.
Sorry for my poor english.

Tabs overlapping content in android

I am creating a project which has 4 tabs , But when i go to the second tab the content of the first tab persists , and when i go to the third tab the content of the previous two tabs persists.
The tab main xml:
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabhost"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"
> </TabWidget>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabcontent"
>
</FrameLayout>
</LinearLayout>
</TabHost>
The java code of the tabmain:
package com.igloo.icebucket;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabMain extends TabActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_main);
TabHost th=(TabHost) findViewById(android.R.id.tabhost);
th.setup();
TabSpec t1=th.newTabSpec("Videos");
TabSpec t2=th.newTabSpec("About challenge");
TabSpec t3=th.newTabSpec("About ALS");
TabSpec t4=th.newTabSpec("About IGLOO");
t1.setIndicator("Videos",getResources().getDrawable(R.drawable.ic_launcher));
Intent i1=new Intent(getApplicationContext(),VideoActivity.class);
t1.setContent(i1);
t2.setIndicator("About challenge",getResources().getDrawable(R.drawable.ic_launcher));
Intent i2=new Intent(getApplicationContext(),AboutChallenge.class);
t2.setContent(i2);
t3.setIndicator("About ALS",getResources().getDrawable(R.drawable.ic_launcher));
Intent i3=new Intent(getApplicationContext(),Aboutals.class);
t3.setContent(i3);
t4.setIndicator("About IGLOO",getResources().getDrawable(R.drawable.ic_launcher));
Intent i4=new Intent(getApplicationContext(),Aboutigloo.class);
t4.setContent(i4);
th.addTab(t1);
th.addTab(t2);
th.addTab(t3);
th.addTab(t4);
}
}
The xml of the first tab:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0067ae"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".VipActivity" >
<LinearLayout
android:id="#+id/titlebar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:background="#e2e2e2"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/videos"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#0067ae" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/titlebar"
android:orientation="vertical" >
<ListView
android:id="#+id/videoList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:background="#f8f8f8" >
</ListView>
</LinearLayout>
</RelativeLayout>
The xml of the second tab:
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/root_aboutchallenge"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT CHALLENGE"
/>
</LinearLayout>
The xml of the third tab:
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/root_aboutals"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT ALS"
/>
</LinearLayout>
The xml of the fourth tab:
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/root_aboutigloo"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT IGLOO"
/>
</LinearLayout>
Please help!!

Why doesn't my view fill the parent?

I have two layouts, this is the parent layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="90"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time: 00:00:00"
android:textColor="#FF0000"
android:textSize="25dip" />
</LinearLayout>
</LinearLayout>
And this is the child layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="Hello World" />
</LinearLayout>
</LinearLayout>
However, when I put the child view in id/layoutTop, it doesn't fill the parent like it's supposed to. This is the result:
This is the code where the id/layoutTop's content is replaced: (This gets called via an event from the child be removed)
public void OnVictory(GamePanel sender, GamePanel next) {
if(next != null){
gamePanel.removeView(sender);
gamePanel.addView(next);
next.triggerOnDisplay();
}else{
Toast.makeText(getBaseContext(), "Victory!", Toast.LENGTH_LONG).show();
}
}
sender is the old view there, next is the one to be put in place, and gamePanel is id/layoutTop
And this is how the inner layout is created:
private void initialize() {
LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.appetizerfakeout,this);
}
Why is my inner view not filling the parent?

Android: Layout short within a ScrollView

I recently just overhauled my application to use ListView instead of using the classic TextView.setText and looping the inflation of a layout. I was able to acheive this very well but now I'm having a problem having it fill the screen. Heres the section of my code that does the work.
//Place JSON data into array one item at a time
JSONArray jArray = new JSONArray(result);
//Loop through each record in the database
//Get ListView
ListView lv= (ListView)findViewById(R.id.listview);
// create the grid item mapping
String[] from = new String[] {"lblQuote", "lblBuzzed", "lblShared", "lblSaid", "lblLikes", "lblHates", "lblLocation", "lblDate"};
int[] to = new int[] { R.id.lblQuote, R.id.lblBuzzed, R.id.lblShared, R.id.lblSaid, R.id.lblLikes, R.id.lblHates, R.id.lblLocation, R.id.lblDate };
for(int i=0;i<jArray.length();i++){
Log.i("uDrew Debug", "Made it into JSONArray Loop");
//Get this record
JSONObject json_data = jArray.getJSONObject(i);
//Put each result into variables for later handling
strFName = json_data.getString("FName");
strLInitial = json_data.getString("LInitial");
strCity = json_data.getString("City");
strState = json_data.getString("State");
strDate = json_data.getString("Date");
strQuote = json_data.getString("Quote");
intLikes = Integer.parseInt(json_data.getString("Likes"));
intHates = Integer.parseInt(json_data.getString("Hates"));
strFNameSaid = json_data.getString("FNameSaid");
strLInitialSaid = json_data.getString("LInitialSaid");
intBuzz = Integer.parseInt(json_data.getString("Buzz"));
Log.i("uDrew Debug", "Made it past JSON Parsing");
switch(intBuzz){
case 1:
strBuzzed = ("One Beer\nSyndrome");
break;
case 2:
strBuzzed = ("Buzzed");
break;
case 3:
strBuzzed = ("Drunk");
break;
case 4:
strBuzzed = ("Trashed");
break;
case 5:
strBuzzed = "Retarded";
break;
}
HashMap<String, String> map = new HashMap<String, String>();
map.put("lblQuote", strQuote);
map.put("lblBuzzed", strBuzzed);
map.put("lblShared", strFName + " " + strLInitial);
map.put("lblSaid",strFNameSaid + " " + strLInitialSaid);
map.put("lblDate", strDate);
map.put("lblLocation", strCity + ", " + strState);
map.put("lblLikes", intLikes.toString());
map.put("lblHates", intHates.toString());
fillMaps.add(map);
}//End For loop
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.myviews, from, to);
lv.setAdapter(adapter);
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:id="#+id/myMainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView android:id="#+id/adViewer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14de539f600385"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="RandomDrunkQuotes.com"
android:id="#+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal"/>
<!-- List Divider -->
<View android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<!-- ListView (grid_items) -->
<LinearLayout android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ListView android:id="#+id/listview"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
myviews.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblQuote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Filler Text"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left">
<ImageView
android:id="#+id/imgUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:src="#drawable/thumbsup"
android:layout_gravity="left"/>
<TextView
android:id="#+id/lblLikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:textSize="4pt"
android:text="10"
android:layout_gravity="left"/>
<TextView
android:id="#+id/lblBuzzedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="Buzz Level:"/>
<TextView
android:id="#+id/lblShared"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Shared By: Filler Name"
android:textSize="4pt"/>
<TextView
android:id="#+id/lblSaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Said By: Filler Name"
android:textSize="4pt"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left">
<ImageView
android:id="#+id/imgDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:src="#drawable/thumbsdn"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblHates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingLeft="5px"
android:paddingRight="5px"
android:textSize="4pt"
android:text="2"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblBuzzed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="High"
android:textSize="4pt"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="04/04/1987 4:32 PM"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/lblLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textSize="4pt"
android:text="Broomfield, CO"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text=" "
android:textSize="1pt"
android:background="#6F7285"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Heres what the App looks like:
There are also no scrollbars and if I change the main.xml ScrolView layout_height="fill_parent" it extends to the end of the screen but the scrollable option isn't there.
Use android:layout_height="fill_parent" in your ScrollView and in the first LinearLayout.
Don't wrap the ListView inside a LinearLayout (the one below the divider View). There's absolutely no need for that.
(Optional) you might want to move the AdView outside the ScollView so it is always visible and not scrolled away
The following code fixed my problem:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:id="#+id/BigLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:id="#+id/myMainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView android:id="#+id/adViewer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14de539f600385"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="RandomDrunkQuotes.com"
android:id="#+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal"/>
<!-- List Divider -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
</LinearLayout>
<!-- ListView (grid_items) -->
<ListView
android:id="#+id/listview"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>

Android tabhost issue...code included

I am getting the following error when I try to launch an activity containing a tabhost.
08-25 16:51:42.551:
ERROR/AndroidRuntime(27863):
java.lang.RuntimeException: Unable to
start activity
ComponentInfo{com.paratransit/com.paratransit.jobDialog}:
java.lang.RuntimeException: Could not
create tab content because could not
find view with id 2131165185
This is my code. Can anyone help?
Java
public Class jobDialog extends TabActivity {
TabHost tabs;
int jobCurrentTab = -1;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
setContentView(R.layout.job_dialog);
tabs = getTabHost();
tabs.setup();
setupTabs();
}
public void setupTabs()
{
TabSpec tspec1 = tabs.newTabSpec("First Tab");
tspec1.setIndicator("Summary", getResources().getDrawable(R.drawable.tab_main)).setContent(R.id.jobDetail1);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec("Second Tab");
tspec2.setIndicator("Details", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.jobDetail2);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec("Third Tab");
tspec3.setIndicator("Notes", getResources().getDrawable(R.drawable.tab_jobs)).setContent(R.id.jobDetail3);
tabs.addTab(tspec3);
XML
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<LinearLayout
android:id="#+id/jobDetail1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/jobDetail2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/jobDetail3"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
</TabHost>
I think the 3 linear layouts, jobDetail1->3 should be within the FrameLayout xml element. The point of the FrameLayout is that all of the views are on top of each other, and thus the tab manager can decide which view to show.
I think you're getting this error because you are not including the LinearLayout inside the FrameLayout, besides I think you need to put some element view inside the LinearLayout's.
Something like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/establecimientoView">
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs" />
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabcontent" >
<LinearLayout
android:id="#+id/tabIdEst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/identificacion_establecimiento"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabRefGeo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/referencia_geografica"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabUbicEstablecimiento"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/ubicacion_establecimiento"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabVialidades"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/entre_vialidades"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

Categories