Dialog or List Preference? - Java for Android App Development

Hi. I have a question.
I have a build a service. Before i start the service, there is an activity. In this Activity the User has 5 Buttons. My Problem now, the user should be able to select an installed app for every Button.
How i can realize it?
My Code looks like this
HTML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<PreferenceCategory
android:key="first_category"
android:title="Einstellungen">
</PreferenceCategory>
<PreferenceScreen
android:defaultValue="false"
android:key="Sub1"
android:summary="Nothing to Change"
android:title="Button 1" />
<PreferenceScreen
android:defaultValue="false"
android:key="Sub2"
android:summary="Nothing to Change"
android:title="Button 2" />
<PreferenceScreen
android:defaultValue="false"
android:key="Sub3"
android:summary="Nothing to Change"
android:title="Button 3" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub4"
android:summaryOff="WhatsApp"
android:summaryOn="Telegram"
android:title="Button 4" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub5"
android:summaryOff="Facebook"
android:summaryOn="Google Play"
android:title="Button 5" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub6"
android:summaryOff="Choose Musik Player"
android:summaryOn="Shuttle"
android:title="Button 6" />
<CheckBoxPreference
android:defaultValue="false"
android:key="Sub7"
android:summaryOff="Gallery"
android:summaryOn="QuickPic"
android:title="Button 7" />
<ListPreference
android:entries="@array/listentries"
android:entryValues="@array/listvalues"
android:key="PREF_LIST"
android:summary="Untertitel"
android:title="Überschrift+Dialog" />
<!--<******.samples.Preferences.WorkingDialogPreference-->
<!--android:dialogIcon="@android:drawable/btn_dialog"-->
<!--android:dialogLayout="@layout/activity_menu_with_overlay"-->
<!--android:dialogMessage="Are you sure you wish to reset your quest progress? This action cannot be undone!"-->
<!--android:key="@string/prefKeyResetQuests"-->
<!--android:negativeButtonText="Cancel"-->
<!--android:positiveButtonText="Clear Quests"-->
<!--android:summary="Reset all quest-progress."-->
<!--android:title="Reset Quests" />-->
</PreferenceScreen>
HTML:
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
public class WorkingDialogPreference extends DialogPreference {
public WorkingDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
When i enable DialogPreference in preferences.xml my app stop. Sry for my bad English, but i hope you will understand.
Thx for Help!

Related

[SOLVED] Broadcast receiver HEADSET_PLUG doesn't work

Dear developers,
After searching the whole internet and stackoverflow I didn't find the answer to my problem, so I need your help.
Problem
I'm trying to make an app that monitors your headset-jack-plug. To code below shows that i register the broadcast receiver and the Logcat output confirms that. But as soon as I test this app on my HTC Desire Bravo (connected to Eclipse), the onreceive method is never called.
When I replace the action.HEADSET_PLUG by action.ACTION_POWER_DISCONNECTED, the code DOES work. So when I unplug my powercable and plug it in again, my Logcat shows me the JackPlugReceiver_debug_tag.
Code
(urls replaced by #### )
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="####"
package="com.wassenaar.antitheft"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.wassenaar.antitheft.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="JackPlugReceiver" >
<intent-filter>
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
</receiver>
</application>
</manifest>
Code:
package com.wassenaar.antitheft;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class JackPlugReceiver extends BroadcastReceiver {
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
Log.d("JackPlugReceiver_debug_tag", "onReceive method of JackPlugReceiver has run!");
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
Log.d("JackPlugReceiver_debug_tag", "Headset is unplugged");
break;
case 1:
Log.d("JackPlugReceiver_debug_tag", "Headset is plugged");
break;
default:
Log.d("JackPlugReceiver_debug_tag", "I have no idea what the headset state is");
}
}
}
}
Logcat
Code:
D/PackageManager(96): Receivers: com.wassenaar.antitheft.JackPlugReceiver
I hope you guys can help me out, I don't know what to do anymore.. Thanks!
Maybe you could share your BroadcastReceiver class and where you register it.
hgpb said:
Maybe you could share your BroadcastReceiver class and where you register it.
Click to expand...
Click to collapse
Stupid, forgot to post that! See the edit above. This is all the code I got.
From what I read, this intent is sent out FLAG_RECEIVER_REGISTERED_ONLY. You won't be able to define the intent in XML
http://stackoverflow.com/questions/6249023/detecting-whether-a-headset-is-plugged-into-an-android-device-or-not/6366238#6366238
Thanks for making this clear. Thought I already tried registering in run time, but apparently I did something wrong. Nevertheless, I learned something new. Thanks for the helpful link to stackoverflow!
Problem solved!

[Q] Can't get ACTION_PACKAGE_ADDED intent to fire

[Solved] I didn't see a place to mark the problem solved, so I did it here so no one would waste their time. Thanks.
I'm trying to get my app to respond anytime a new package is installed.
I have registered the intent in the manifest and created the receiver class, but I can't get onReceive to fire.
While I was playing around with it and trying to debug, I added a constructor to my receiver, and the constructor fires every time that a package is installed. The onReceive method never fires with the constructor in or out though.
I'm not sure where I am going wrong. Anyone have any ideas on what I am doing wrong? Thanks.
Code:
<receiver android:name=".InstallReceiver">
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Code:
public class InstallReceiver extends BroadcastReceiver {
public InstallReceiver()
{
//This log will display in the logcat
Log.d("InstallReceiver", "InstallReceiver constructor called.");
}
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
//This log never displays if the constructor is in or commented out
Log.d("InstallReceiver", "Install detected.");
}
}
Why do you have <category android:name="android.intent.category.DEFAULT" /> in your receiver definition? I assume your app isn't just a broadcast receiver??
It was one of the suggested fixes I found in the hours I've spent searching the internet for answers. It still has the same problem if you remove it though. I guess I just forgot to take that one out before I pasted my code.
I created a new project, and cleared all the data from my phone before uninstalling and then re-installing, and it magically started working. So, I'm not sure what the issue was.
I love the mysterious fixes!

What am I doing wrong?

I am trying to combine 2 android apps through a button. The first app is just a regular screen that has one button on it. The second app is an app launcher that shows all apps and opens them when clicked on. I want to make it so that when i click the button in the first app it opens up the second app. I have looked at questions similiar to mine on Stackexchange and have taken their advice by making the second app into a library and importing it, but when i click the button the app shuts down. Am i missing something?
This is the manifest file for the first app:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/symbol"
android:label="@string/app_name">
<activity
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
android:launchMode="singleTask"
android:name="com.Fuku.Eiko.MainActivity"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
android:launchMode="singleTask"
android:name="com.Assistant.Eiko.AppDrawer"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
This is my xml for button:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/symbol_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
This is the java file for the first app:
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import com.assistant.Eiko.*;
import android.content.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */ @override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(com.assistant.Eiko.R.id.button);
button.setOnClickListener
(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, com.assistant.Eiko.AppDrawer.class);
startActivity(intent);
}
});
}
I have asked this question on StackExchange but no answers yet. Thank you in advance for any help given. Please be as descriptive as possible. Also I am not using eclipse i am using AIDE( android app editor).
Sent from my GT-P3113 using XDA Premium 4 mobile app

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