problem using tabs - Java for Android App Development

Ok so I made my first tab class. Has 3 tabs. Everything works fine but was wondering how make put a class into one of the tabs.
This is my class that contains the tabs:
Code:
public class TABS extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tablayout);
TabHost th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Practise");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("Main Activity");
th.addTab(specs);
specs= th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Pracfg4tise");
th.addTab(specs);
}
}
XML Layout for the tabbed class:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".TABS" >
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 1 Button" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 2 button" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 3 Text View" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
So I have another class called mainactivity. nothing special on it, just a few textviews and buttons and what not. So how do I set up the mainactivity into the tabs so that if i press the tab that says 'Main Activity', it will take me to the main activity class.

When setting the "setIndicator" property is where I set my class back when I used TabHost's.
Code:
fourthTabSpec.setIndicator("BlackList", res.getDrawable(R.drawable.blacklist_32)).setContent(new Intent(this,BlackList.class));
There is a different way to do this now using fragments though

Hi,
in my application i used tabs too, the main class that contains tabs usually extends TabsActivity
Then, to use another class as content of a tab just use intents, here a sample:
Intent lendsActivityIntent = new Intent(this,LendsActivity.class);
Intent objectsActivityIntent = new Intent(this,ObjectsActivity.class);
firstTabSpec.setIndicator(getString(R.string.lends_tab), getResources().getDrawable(R.drawable.ic_lends)).setContent(lendsActivityIntent);
secondTabSpec.setIndicator(getString(R.string.objects_tab), getResources().getDrawable(R.drawable.ic_catalogue)).setContent(objectsActivityIntent);

calavera69 said:
Hi,
in my application i used tabs too, the main class that contains tabs usually extends TabsActivity
Then, to use another class as content of a tab just use intents, here a sample:
Intent lendsActivityIntent = new Intent(this,LendsActivity.class);
Intent objectsActivityIntent = new Intent(this,ObjectsActivity.class);
firstTabSpec.setIndicator(getString(R.string.lends_tab), getResources().getDrawable(R.drawable.ic_lends)).setContent(lendsActivityIntent);
secondTabSpec.setIndicator(getString(R.string.objects_tab), getResources().getDrawable(R.drawable.ic_catalogue)).setContent(objectsActivityIntent);
Click to expand...
Click to collapse
I did forget to mention it needs to extend TabActivity

The recommended way is to do it using tabs in the ActionBar now.
Google just released its new support-v7 library which brings the ActionBar to apps on Android 2.1 and above.
So there is really no excuse not to use it anymore.

Related

[Q] ListView doesn't use fill_parent

I have made a sidebar and want to display little screenshots in the sidebar. The ListView contains a LinearLayout with an ImageView. The ListView should take the full screen height, but it is only as big as one item. How must I change the xml to get the ListView using full screenheight?
Thanks in advance
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/firstlin"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollbars="none">
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent">
<ScrollView android:id="@+id/ScrollView01"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#D8D8D8"
android:scrollbars="none">
<LinearLayout android:id="@+id/LinearLayout09"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="fill_parent">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
I dont understand why you have a scrollview. A listview scrolls. You have 2 moving parts
Thank you
I didn't no that a listview scrolls - i removed the scrollview, now everythink work.
Kotake

how to get AdMob ads to show up at the top of my screen.

I've got AdMob working in my app, but it's showing up at the bottom of my screen. Does anyone know how to force it to the top of the screen? I don't wont to use RelativeLayout as I already have a bunch of stuff set up with my LinearLayout.
I'm initiating AdMob via an @id reference in my main.xml and some calls in the java activity:
Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/linearLayout" .....this is the only line I added for my Admob reference
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView android:id="@+id/ImageView01"
android:src="@drawable/image01"
android:layout_height="150dp"
android:layout_width="200dp"
android:scaleType="centerCrop"
android:paddingTop="10px">
</ImageView>
</LinearLayout>
Bla, Bla, Bla...more layout stuff
Then I have this in my java activity...
Code:
setContentView(R.layout.main);
//create an adView
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
String pubID = "a14d9cfd23d60cf";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
layout.addView(adView);
AdRequest request = new AdRequest();
//request.setTesting(true);
adView.loadAd(request);
Never mind...I got it figured out. It's all about where you place the layout id. If I move android:id="@+id/linearLayout" down into the LinearLayout just below the one it's in now, My ad shows at the top.

New to android app development...switching between views or layouts or activities...

Hi,
i am new to developing apps on Android (Windows Phone 7 dev)...how ever i have created my first project (i am a Java developer for many years now, so i really have only problems with Android specific things).
And i already have my first problem and i have not enough knowledge to find the tutorials that i need for this or maybe i am just doing something wrong.
I have a main.xml file and a logon.xml file for the 2 different views (or how ever you call that) i need...i like to switch to logon.xml if i tap a button on main.xml. That works very well (i am using setContentView(R.layout.logon) so far but i am missing the animation between the two UIs...and so far none of the tutorials i have found are working with my scenario...can someone help me out?
I just know how easy it is in Windows Phone 7 to switch between panels with animations created in expression blend
main.xml
Code:
<?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:orientation="vertical">
<TextView android:layout_width="150dip" android:text="" android:id="@+id/space" android:layout_height="wrap_content"></TextView>
<TextView android:id="@+id/InformationCreateNewAccount" android:layout_height="wrap_content" android:text="Don't have a Account?" android:layout_width="wrap_content"></TextView>
<Button android:id="@+id/btnCreateNewAccount" android:onClick="goToLoginView" android:layout_height="wrap_content" android:text="Create" android:layout_width="150dip"></Button>
<TextView android:text="" android:id="@+id/space" android:layout_width="150dip" android:layout_height="wrap_content"></TextView>
<TextView android:layout_width="wrap_content" android:id="@+id/InformationHaveAAccount" android:layout_height="wrap_content" android:text="Already have a Account?"></TextView>
<Button android:id="@+id/btnSignIn" android:layout_width="150dip" android:layout_height="wrap_content" android:text="Sign in"></Button>
</LinearLayout>
logon.xml
Code:
<?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">
</LinearLayout>
chatClient.java
Code:
package com.ayra.chat.com.ayra;
import com.ayra.chat.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class chat extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void goToLoginView(View view) {
setContentView(R.layout.logon);
}
}

TextView shows wrong text

Hi,
i'm reading a book about android app development (Learn Android App Development by Wallace Jackson).
But i'm having troubles with my TextViews..
This is what i get when i open the app on the android emulator:
It is supposed to show data like the planet name, mass, gravity,... I tried to locate the mistake in the code, but i never found it..
I want to copy paste the code, but maybe it's easier if i post the entire project
https://www.dropbox.com/sh/235c7k0psaoejxk/I903eizE7A
Could anyone help me find the bug? :/
I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...
Thanks
coolbud012 said:
I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...
Thanks
Click to expand...
Click to collapse
Oh yeah sorry, I didn't think of that.
This is the XML:
Code:
<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"
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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/dataView1"
android:layout_toRightOf="@+id/textView1"
android:layout_marginLeft="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label"
android:layout_below="@+id/textView1"/>
<TextView
android:id="@+id/dataView2"
android:layout_toRightOf="@+id/textView2"
android:layout_alignStart="@+id/dataView1"
android:layout_below="@+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label"
android:layout_below="@+id/textView2"/>
<TextView
android:id="@+id/dataView3"
android:layout_toRightOf="@+id/textView3"
android:layout_alignStart="@+id/dataView2"
android:layout_below="@+id/dataView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label"
android:layout_below="@+id/textView3"/>
<TextView android:id="@+id/dataView4"
android:layout_toRightOf="@+id/textView4"
android:layout_alignStart="@+id/dataView3"
android:layout_below="@+id/dataView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label"
android:layout_below="@+id/textView4"/>
<TextView
android:id="@+id/dataView5"
android:layout_toRightOf="@+id/textView5"
android:layout_alignStart="@+id/dataView4"
android:layout_below="@+id/dataView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label"
android:layout_below="@+id/textView5"/>
<TextView
android:id="@+id/dataView6"
android:layout_toRightOf="@+id/textView6"
android:layout_alignStart="@+id/dataView5"
android:layout_below="@+id/dataView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label"
android:layout_below="@+id/textView6"/>
<TextView
android:id="@+id/dataView7"
android:layout_toRightOf="@+id/textView7"
android:layout_alignStart="@+id/dataView6"
android:layout_below="@+id/dataView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"
android:layout_below="@+id/textView7"/>
<TextView
android:id="@+id/dataView8"
android:layout_toRightOf="@+id/textView8"
android:layout_alignStart="@+id/dataView7"
android:layout_below="@+id/dataView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"/>
</RelativeLayout>
And this is the java:
Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
WorldGen earth = new WorldGen("Earth", 5973, 9.78);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setStartUpWorldValues();
}
protected void setStartUpWorldValues() {
earth.setPlanetColonies(1);
earth.setPlanetMilitary(1);
earth.setColonyImmigration(1000);
earth.setBaseProtection(100);
earth.turnForceFieldOn();
}
@SuppressWarnings("unused")
private void setStartUpScreenText() {
TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
planetNameValue.setText(earth.planetName);
TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
planetMassValue.setText(String.valueOf(earth.planetMass));
TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
planetGravityValue.setText(String.valueOf(earth.planetGravity));
TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
planetColoniesValue.setText(String.valueOf(earth.planetColonies));
TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
planetBasesValue.setText(String.valueOf(earth.planetBases));
TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Xintax said:
Oh yeah sorry, I didn't think of that.
This is the XML:
Code:
<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"
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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/dataView1"
android:layout_toRightOf="@+id/textView1"
android:layout_marginLeft="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label"
android:layout_below="@+id/textView1"/>
<TextView
android:id="@+id/dataView2"
android:layout_toRightOf="@+id/textView2"
android:layout_alignStart="@+id/dataView1"
android:layout_below="@+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label"
android:layout_below="@+id/textView2"/>
<TextView
android:id="@+id/dataView3"
android:layout_toRightOf="@+id/textView3"
android:layout_alignStart="@+id/dataView2"
android:layout_below="@+id/dataView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label"
android:layout_below="@+id/textView3"/>
<TextView android:id="@+id/dataView4"
android:layout_toRightOf="@+id/textView4"
android:layout_alignStart="@+id/dataView3"
android:layout_below="@+id/dataView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label"
android:layout_below="@+id/textView4"/>
<TextView
android:id="@+id/dataView5"
android:layout_toRightOf="@+id/textView5"
android:layout_alignStart="@+id/dataView4"
android:layout_below="@+id/dataView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label"
android:layout_below="@+id/textView5"/>
<TextView
android:id="@+id/dataView6"
android:layout_toRightOf="@+id/textView6"
android:layout_alignStart="@+id/dataView5"
android:layout_below="@+id/dataView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label"
android:layout_below="@+id/textView6"/>
<TextView
android:id="@+id/dataView7"
android:layout_toRightOf="@+id/textView7"
android:layout_alignStart="@+id/dataView6"
android:layout_below="@+id/dataView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"
android:layout_below="@+id/textView7"/>
<TextView
android:id="@+id/dataView8"
android:layout_toRightOf="@+id/textView8"
android:layout_alignStart="@+id/dataView7"
android:layout_below="@+id/dataView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"/>
</RelativeLayout>
And this is the java:
Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
WorldGen earth = new WorldGen("Earth", 5973, 9.78);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setStartUpWorldValues();
}
protected void setStartUpWorldValues() {
earth.setPlanetColonies(1);
earth.setPlanetMilitary(1);
earth.setColonyImmigration(1000);
earth.setBaseProtection(100);
earth.turnForceFieldOn();
}
@SuppressWarnings("unused")
private void setStartUpScreenText() {
TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
planetNameValue.setText(earth.planetName);
TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
planetMassValue.setText(String.valueOf(earth.planetMass));
TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
planetGravityValue.setText(String.valueOf(earth.planetGravity));
TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
planetColoniesValue.setText(String.valueOf(earth.planetColonies));
TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
planetBasesValue.setText(String.valueOf(earth.planetBases));
TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
Have gone through this but didnt get what exactly you are trying to achieve...Also you have posted the main Activity in which you have created a member of "WorldGen" , whats in this class?
Actually to be frank I didnt get what exactly you are trying to do here...
I would be good if you make an image in "Paint" , rough image, and show what you are exactly trying to achieve?
Thanks
---------- Post added at 09:07 PM ---------- Previous post was at 09:06 PM ----------
If possible upload the project on Github.com
Well i'm trying to get the text on the left to change into the planet name (earth) planet gravity (9.8),...
I think i can't make it more clear with a paint image with my painting skills
I'm setting up github as we speak, i'll upload it in a sec.
EDIT: Here it is: https://github.com/Xintax/HlloWrld
Thanks!
Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?
Regards
Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.
EmptinessFiller said:
Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?
Regards
Click to expand...
Click to collapse
SimplicityApks said:
Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.
Click to expand...
Click to collapse
Well i tried to hard-code the values, and that works.. But my idea is that users can change the planet, and can make their own, so i can't hard-code the values because then they can't change :/
I'll try if the listview works, it does take a long time

Changing screen content from Navigation Drawer

I am creating app with navigation drawer. There are a lot of examples of creating such apps, but all examples show only how to change one framgent, I mean that activity has only one main fragment with content.
Here is example of such layout from offical docs.
Code:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
In this case we are replacing content of content_frame layout with another fragment.
But in my case, I have two fragments on my activity, here is my layout.
Code:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_actionbar">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/first_fragment"
/>
<View
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="@android:color/darker_gray"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/second_fragment"
>
</FrameLayout>
</LinearLayout>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment
android:id="@+id/fragment_drawer"
android:name=".NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
So in my case I have two fragment containers for holding differen fragments.
SO I am writing here to get some advices what approach should I follow in this case.
Create wrapper for two fragments ? And this two layouts will be nested.
Change two fragments if it is required.
Open new activity each time user clicks on item in NavDraw menu ?
Something other ?
Some options in NavDraw menu will open new activity, because it has quite different interface and logic, but there are some screens that can be displayed with the help of replacing fragment.
Also my first_fragment will be present on most pages, so maybe it will be acсeptable way to updating UI in my case.
I want to follow all UI design and building app approaches in order to create responsive app.
Please suggest what is the most acceptable way to implement this.
Thanks in advance.

Categories

Resources