TextView shows wrong text - Java for Android App Development

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

Related

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);
}
}

problem using tabs

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.

listView Resize animation

I have this custom listView:
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableRow">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/imdDesc" />
<TextView
android:id="@+id/titleList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="25sp"
android:autoText="false"
android:gravity="center_vertical|center|center_horizontal" />
</TableRow>
This adapter:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] title;
private final int[] colors;
private final Integer[] imageId;
public CustomList(Activity context,String[] title,int[] colors, Integer[] imageId) {
super(context, R.layout.list_single, title);
this.context = context;
this.title = title;
this.imageId = imageId;
this.colors=colors;
}
@override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titleList);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(title[position]);
txtTitle.setTextColor(Color.parseColor("#FFffffff"));
txtTitle.setBackgroundColor(colors[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
and this is how I bind them:
final CustomList adapter = new
CustomList(MainActivity.this, title, colors, imageId);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
My list has 12 items. I need to resize the list when user click one item. If the user choses an Item for the first time, the list has to change its width to 1/3 of its original size and to double the height of the selected item. If an item is already selected in the list and the user selects another the old item has to go back to the original height and the new selected one has to double its height without any width changes.
I want to animate all the resizing for nice looking.
This is the animation for changing width:
public class ShrinkList extends Animation
{
int fromWidth;
View view;
int def;
public ShrinkList(View view) {
this.view = view;
this.fromWidth = view.getWidth();
def=fromWidth/3;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
newWidth = (int) ((def - fromWidth) * interpolatedTime + fromWidth);
if (newWidth > def/3) {
view.getLayoutParams().width = newWidth;
view.requestLayout();
}
else{
view.getLayoutParams().width = def/3;
view.requestLayout();
}
}
}
and this one is for changing height:
public class Grow extends Animation
{
int fromHeight;
View view;
int defaultHeight;
public Grow(View view,int height) {
this.view = view;
this.fromHeight = view.getHeight();
defaultHeight=height;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
newHeight = (int) (fromHeight / (1 - interpolatedTime));
if (newHeight < defaultHeight * 2) {
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
else{
view.getLayoutParams().height = defaultHeight*2;
view.requestLayout();
}
}
}
and I play them like that:
if(h==0) { //first time the user selects an item =>change width and height
Animation a = new ShrinkList(list);
a.setInterpolator(new LinearInterpolator());
a.setDuration(1000);
list.setAnimation(a);
list.startAnimation(a);
}
Animation a1 = new Grow(view,height); //change only height
a1.setInterpolator(new LinearInterpolator());
a1.setDuration(300);
view.setAnimation(a1);
view.startAnimation(a1);
My problem is that when the list changes its width, the animation is not smooth at all and it only changes the width, not the height too.
How can I make the animation smoother and make the two animations play at once?
I have tried scaling the list, but that scales all the list. basically I need only to resize the textView within ListView nd changing layoutParams does that.
I have tried to insert the code from Grow.java into ShrinkList.Java in orefer to play both animations once and it only played the one from Grow.java.
Jaws1992 said:
I have this custom listView:
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableRow">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/imdDesc" />
<TextView
android:id="@+id/titleList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="25sp"
android:autoText="false"
android:gravity="center_vertical|center|center_horizontal" />
</TableRow>
This adapter:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] title;
private final int[] colors;
private final Integer[] imageId;
public CustomList(Activity context,String[] title,int[] colors, Integer[] imageId) {
super(context, R.layout.list_single, title);
this.context = context;
this.title = title;
this.imageId = imageId;
this.colors=colors;
}
@override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titleList);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(title[position]);
txtTitle.setTextColor(Color.parseColor("#FFffffff"));
txtTitle.setBackgroundColor(colors[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
and this is how I bind them:
final CustomList adapter = new
CustomList(MainActivity.this, title, colors, imageId);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
My list has 12 items. I need to resize the list when user click one item. If the user choses an Item for the first time, the list has to change its width to 1/3 of its original size and to double the height of the selected item. If an item is already selected in the list and the user selects another the old item has to go back to the original height and the new selected one has to double its height without any width changes.
I want to animate all the resizing for nice looking.
This is the animation for changing width:
public class ShrinkList extends Animation
{
int fromWidth;
View view;
int def;
public ShrinkList(View view) {
this.view = view;
this.fromWidth = view.getWidth();
def=fromWidth/3;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
newWidth = (int) ((def - fromWidth) * interpolatedTime + fromWidth);
if (newWidth > def/3) {
view.getLayoutParams().width = newWidth;
view.requestLayout();
}
else{
view.getLayoutParams().width = def/3;
view.requestLayout();
}
}
}
and this one is for changing height:
public class Grow extends Animation
{
int fromHeight;
View view;
int defaultHeight;
public Grow(View view,int height) {
this.view = view;
this.fromHeight = view.getHeight();
defaultHeight=height;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
newHeight = (int) (fromHeight / (1 - interpolatedTime));
if (newHeight < defaultHeight * 2) {
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
else{
view.getLayoutParams().height = defaultHeight*2;
view.requestLayout();
}
}
}
and I play them like that:
if(h==0) { //first time the user selects an item =>change width and height
Animation a = new ShrinkList(list);
a.setInterpolator(new LinearInterpolator());
a.setDuration(1000);
list.setAnimation(a);
list.startAnimation(a);
}
Animation a1 = new Grow(view,height); //change only height
a1.setInterpolator(new LinearInterpolator());
a1.setDuration(300);
view.setAnimation(a1);
view.startAnimation(a1);
My problem is that when the list changes its width, the animation is not smooth at all and it only changes the width, not the height too.
How can I make the animation smoother and make the two animations play at once?
I have tried scaling the list, but that scales all the list. basically I need only to resize the textView within ListView nd changing layoutParams does that.
I have tried to insert the code from Grow.java into ShrinkList.Java in orefer to play both animations once and it only played the one from Grow.java.
Click to expand...
Click to collapse
Do it like this
Code:
<RelativeLayout
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]/>
</RelativeLayout>
Then you only need to change the width and height. And you don't have to worry about the animation
Rick Clephas said:
Do it like this
Code:
<RelativeLayout
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]/>
</RelativeLayout>
Then you only need to change the width and height. And you don't have to worry about the animation
Click to expand...
Click to collapse
I have tried what you suggested and the relative layout works great, but the list doesn't animate when it changes its witdh
Jaws1992 said:
I have tried what you suggested and the relative layout works great, but the list doesn't animate when it changes its witdh
Click to expand...
Click to collapse
You should add the animate layout changes to the first parent with match_parent as width
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
You should add the animate layout changes to the first parent with match_parent as width
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
I created a relative layout as in your example and added animate layout changes to both the listview and that layout and changed the witth of the layout and it doesn't animate the list getting smaller. Only the next relative layout getting bigger after the list is small
Jaws1992 said:
I created a relative layout as in your example and added animate layout changes to both the listview and that layout and changed the witth of the layout and it doesn't animate the list getting smaller. Only the next relative layout getting bigger after the list is small
Click to expand...
Click to collapse
Okey. AnimateLayoutChanges applies to the chields. So if you want to animate the relative layout the listview is in. You need to add animateLayoutChanges to his parent
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Okey. AnimateLayoutChanges applies to the chields. So if you want to animate the relative layout the listview is in. You need to add animateLayoutChanges to his parent
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
I added animate layout changes to all the listView ancestors and it still doesn't animate the listView.
This is the java code for changing width. Maybe I doing something wrong here:
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) linLay.getLayoutParams();
if(sdkVersion>=Build.VERSION_CODES.HONEYCOMB) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
lp.width =size.x/3;
}
else{
Display display = getWindowManager().getDefaultDisplay();
lp.width = display.getWidth()/3;
}
linLay.setLayoutParams(lp); //linLay is the listView parrent and is a relativeLayout
Jaws1992 said:
I added animate layout changes to all the listView ancestors and it still doesn't animate the listView.
This is the java code for changing width. Maybe I doing something wrong here:
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) linLay.getLayoutParams();
if(sdkVersion>=Build.VERSION_CODES.HONEYCOMB) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
lp.width =size.x/3;
}
else{
Display display = getWindowManager().getDefaultDisplay();
lp.width = display.getWidth()/3;
}
linLay.setLayoutParams(lp); //linLay is the listView parrent and is a relativeLayout
Click to expand...
Click to collapse
You have to set the animateLayoutChanges to the paretn of linLay
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
You have to set the animateLayoutChanges to the paretn of linLay
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Yes, I have already done that.As I said, I added animate layout changes to all of the listview ancestosr meaning linLay, parent of linLay, parent of parent of linLay and so on until the root of layouts, but the listView still doesn't animate
Okey could you post your xml
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Okey could you post your xml
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
<LinearLayout
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:id="@+id/titleLayout"
android:visibility="visible"
android:animateLayoutChanges="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imagew"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/share"
android:layout_alignEnd="@+id/share"
android:layout_toRightOf="@+id/imagew"
android:layout_toEndOf="@+id/imagew"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/title"
android:textSize="40sp"
android:gravity="center|right"
android:layout_gravity="left"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/date"
android:textSize="30sp"
android:gravity="clip_horizontal|center|center_horizontal"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:textColor="#ffffffff"
android:textStyle="italic" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/share"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="@drawable/share"
android:adjustViewBounds="false"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="false"
android:layout_centerVertical="true"
android:contentDescription="@string/share" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linLay"
android:animateLayoutChanges="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:headerDividersEnabled="false"
android:dividerHeight="0dp"
android:animateLayoutChanges="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_toRightOf="@id/linLay"
android:id="@+id/contentLayout"
android:animateLayoutChanges="true">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="30sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"
android:textColor="#ffffffff"
android:typeface="normal"
android:gravity="left|fill" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="#ff647ab1"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:background="@drawable/fb" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/FB"
android:id="@+id/fb"
android:textColor="#ffffffff"
android:textStyle="bold"
android:textSize="50sp" />
</LinearLayout>
<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="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Jaws1992 said:
<LinearLayout
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:id="@+id/titleLayout"
android:visibility="visible"
android:animateLayoutChanges="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imagew"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/share"
android:layout_alignEnd="@+id/share"
android:layout_toRightOf="@+id/imagew"
android:layout_toEndOf="@+id/imagew"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/title"
android:textSize="40sp"
android:gravity="center|right"
android:layout_gravity="left"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/date"
android:textSize="30sp"
android:gravity="clip_horizontal|center|center_horizontal"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:textColor="#ffffffff"
android:textStyle="italic" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/share"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="@drawable/share"
android:adjustViewBounds="false"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="false"
android:layout_centerVertical="true"
android:contentDescription="@string/share" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linLay"
android:animateLayoutChanges="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:headerDividersEnabled="false"
android:dividerHeight="0dp"
android:animateLayoutChanges="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_toRightOf="@id/linLay"
android:id="@+id/contentLayout"
android:animateLayoutChanges="true">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="30sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"
android:textColor="#ffffffff"
android:typeface="normal"
android:gravity="left|fill" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="#ff647ab1"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:background="@drawable/fb" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/FB"
android:id="@+id/fb"
android:textColor="#ffffffff"
android:textStyle="bold"
android:textSize="50sp" />
</LinearLayout>
<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="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Click to expand...
Click to collapse
Does the width change?
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Does the width change?
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Yes. The width of changes, but it doesn't animate
Jaws1992 said:
Yes. The width of changes, but it doesn't animate
Click to expand...
Click to collapse
Okey I don't get it. It should work...
Sent from my SM-N9005 using XDA Premium 4 mobile app

[Q] ListView appearance changes

I have created an android program which contains listview. Emulator and my phone (Samsung Galaxy S) shows like;
-see First Attachment (1.png)
But when I open my program in Samsung Note 3, it shows like;
-see Second Attachment (2.png)
It likes 2 empty rows(empty but their colors dark blue) and 1 real list view item. 2 empty rows, 1 real item, 2 empty rows, 1 real item ....
I tried each of item in listview. I removed each one and it does not solve my problem. And some bigger screen phones have same issue. How can i solve it?
my xml:
Code:
<RelativeLayout
android:id="@+id/tabTT"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/tabTT_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team Tactics"
android:id="@+id/tabTT_main_text"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#800000"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_main_second"
android:textSize="12sp"
android:textColor="#000000"
android:visibility="invisible"
android:layout_below="@id/tabTT_main_text"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabTT_listView"
android:clickable="true"
android:layout_below="@id/tabTT_main_second"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ImageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_name"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_subName"
android:textSize="12sp"
android:layout_below="@id/tabTT_textView_name"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ProgressBar"
android:layout_below="@id/tabTT_textView_subName"
android:layout_toRightOf="@id/tabTT_ImageView"
android:progressDrawable="@drawable/progress_bar"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_percentage"
android:layout_centerHorizontal="true"
android:layout_below="@id/tabTT_textView_subName"
android:textColor="#800000"/>
</RelativeLayout>
my adapter:
Code:
public static class TTAdapter extends ArrayAdapter<Achievement> {
public TTAdapter(Context context, ArrayList<Achievement> users) {
super(context, 0, users);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Achievement user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_ach, parent, false);
}
convertView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Achievement clicked = getItem(position);
if(clicked.progressFloatSecond!=-1){
Toast.makeText(getContext(), "Left: " + NumberFormat.getNumberInstance(Locale.US).format(clicked.progressFloatSecond - clicked.progressFloatFirst), Toast.LENGTH_SHORT).show();
}
else Toast.makeText(getContext(), "One-Time Mission!", Toast.LENGTH_SHORT).show();
}
});
TextView name = (TextView) convertView.findViewById(R.id.tabTT_textView_name);
TextView subName = (TextView) convertView.findViewById(R.id.tabTT_textView_subName);
ImageView imVi = (ImageView)convertView.findViewById(R.id.tabTT_ImageView);
ProgressBar progBar = (ProgressBar) convertView.findViewById(R.id.tabTT_ProgressBar);
TextView percentageFloat = (TextView) convertView.findViewById(R.id.tabTT_textView_percentage);
DecimalFormat df = new DecimalFormat("##.##");
name.setText(user.name);
subName.setText(user.subName);
imVi.setImageResource(user.picInt);
progBar.setVisibility(View.INVISIBLE);
percentageFloat.setVisibility(View.INVISIBLE);
if(user.progressFloatSecond!=-1){
progBar.setVisibility(View.VISIBLE);
progBar.setMax(user.progressFloatSecond);
progBar.setProgress(user.progressFloatFirst);
percentageFloat.setText(df.format(user.progressFloat) + " %");
percentageFloat.setVisibility(View.VISIBLE);
}
return convertView;
}
}
Maybe you can try the layout development tool to show the view border.
Open it in Settings->Developer options->Show layout bounds.
anilff said:
I have created an android program which contains listview. Emulator and my phone (Samsung Galaxy S) shows like;
-see First Attachment (1.png)
But when I open my program in Samsung Note 3, it shows like;
-see Second Attachment (2.png)
It likes 2 empty rows(empty but their colors dark blue) and 1 real list view item. 2 empty rows, 1 real item, 2 empty rows, 1 real item ....
I tried each of item in listview. I removed each one and it does not solve my problem. And some bigger screen phones have same issue. How can i solve it?
my xml:
Code:
<RelativeLayout
android:id="@+id/tabTT"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/tabTT_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team Tactics"
android:id="@+id/tabTT_main_text"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#800000"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_main_second"
android:textSize="12sp"
android:textColor="#000000"
android:visibility="invisible"
android:layout_below="@id/tabTT_main_text"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabTT_listView"
android:clickable="true"
android:layout_below="@id/tabTT_main_second"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ImageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_name"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_subName"
android:textSize="12sp"
android:layout_below="@id/tabTT_textView_name"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ProgressBar"
android:layout_below="@id/tabTT_textView_subName"
android:layout_toRightOf="@id/tabTT_ImageView"
android:progressDrawable="@drawable/progress_bar"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_percentage"
android:layout_centerHorizontal="true"
android:layout_below="@id/tabTT_textView_subName"
android:textColor="#800000"/>
</RelativeLayout>
my adapter:
Code:
public static class TTAdapter extends ArrayAdapter<Achievement> {
public TTAdapter(Context context, ArrayList<Achievement> users) {
super(context, 0, users);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Achievement user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_ach, parent, false);
}
convertView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Achievement clicked = getItem(position);
if(clicked.progressFloatSecond!=-1){
Toast.makeText(getContext(), "Left: " + NumberFormat.getNumberInstance(Locale.US).format(clicked.progressFloatSecond - clicked.progressFloatFirst), Toast.LENGTH_SHORT).show();
}
else Toast.makeText(getContext(), "One-Time Mission!", Toast.LENGTH_SHORT).show();
}
});
TextView name = (TextView) convertView.findViewById(R.id.tabTT_textView_name);
TextView subName = (TextView) convertView.findViewById(R.id.tabTT_textView_subName);
ImageView imVi = (ImageView)convertView.findViewById(R.id.tabTT_ImageView);
ProgressBar progBar = (ProgressBar) convertView.findViewById(R.id.tabTT_ProgressBar);
TextView percentageFloat = (TextView) convertView.findViewById(R.id.tabTT_textView_percentage);
DecimalFormat df = new DecimalFormat("##.##");
name.setText(user.name);
subName.setText(user.subName);
imVi.setImageResource(user.picInt);
progBar.setVisibility(View.INVISIBLE);
percentageFloat.setVisibility(View.INVISIBLE);
if(user.progressFloatSecond!=-1){
progBar.setVisibility(View.VISIBLE);
progBar.setMax(user.progressFloatSecond);
progBar.setProgress(user.progressFloatFirst);
percentageFloat.setText(df.format(user.progressFloat) + " %");
percentageFloat.setVisibility(View.VISIBLE);
}
return convertView;
}
}
Click to expand...
Click to collapse

Categories

Resources