FAQ Database Discussion Community


At what point in the View lifecycle should I unsubscribe if the View is never made visible?

android,android-view,rx-java,rx-android
I have a View that converts some text to a localised version of that text using an API. This works if the View is visible in the layout because once the View gets destroy onDetachedFromWindow() gets called. However if the View is invisible and never gets attached to the Window...

FrameLayout IllegalStateException: The specified child already has a parent

java,android,android-layout,android-view
I'm having this error in a Dialog instantiated from a PreferenceActivity. Can someone tell me what is wrong? public class NumberPickerPreference extends DialogPreference { public static final int MAX_VALUE = 24; public static final int MIN_VALUE = 2; public NumberPicker picker; FrameLayout dialogView; private int value; Context ctx; public NumberPickerPreference(Context...

Add view by sliding in from left

android,android-animation,android-view
I want to add a view to a fragment via an animation. I want the view to appear by sliding in from the left of the screen and exit by sliding out the same way. I'm not able to get this to work. When the fragment appears, the view is...

Update ListView footer

android,android-listview,android-view,android-view-invalidate
I've a ListView with a footer View that contains a TextView that can be changed dynamically according to the language selected. When I select a different language I update my ListView items: mBaseAdapter.updateItems(items); BaseAdapter: public void updateItems(List<Map.Entry<Integer, String>> items) { mItemsResIdList = new ArrayList<>(items); notifyDataSetChanged(); } And to update my...

Android ScrollView, check if currently scrolling

java,android,android-listview,android-view,android-scrollview
Is there a way to check if a standard ScrollView is currently being scrolled? Doesn't matter if the direction is upwards or downwards, i only need to check whether it's currently being scrolled at all....

Custom View: Canvas draw methods give API error

android,android-studio,android-canvas,android-view
I created a custom view and overrode the onDraw method. However, Android Studio says my canvas.drawOval and canvas.drawArc calls require I set my minimum API to 21. Canvas has been around since API 1 right? import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.Button; public class PieButton extends Button...

No resource identifier found for attribute ' ' in package 'com.app…'

android,android-studio,android-view,android-custom-view
I've imported a project from eclipse to Android studio. it utilizes a custom view xmlns:app="http://schemas.android.com/apk/res-auto" I get errors in the lines below from activity_ro.xml file like " Error:(136) No resource identifier found for attribute 'pstsTabPaddingLeftRight' in package 'com.app.xxxx'" app:pstsDividerColor="#00000000" app:pstsIndicatorColor="#FF33B5E6" app:pstsTabPaddingLeftRight="14dip" app:pstsUnderlineColor="#FF33B5E6" /> I'm not sure if custom views different...

How to approach custom Layout

android,android-layout,android-view
I'm trying to create a custom UI element (blue in the picture), that would be placed inside a regular RelativeLayout (it would be used 2 or 3 times). The View must contain TextView, ImageButtons and similar widgets. I've read up on custom Views, ViewGroups, but I don't know which one...

How do I update my TextView in MainActivity after exiting a dialog fragment?

android,android-layout,android-fragments,android-view,android-timepicker
Currently, my main activity displays an arbitrary time, and holds a button that when pressed, brings up a Time Picker Dialog Fragment. After the user sets a new time in the Fragment, closing the fragment, I want my main activity to update it's TextView with the new time the user...

When are views attached and detached?

android,android-view
This question is not about how to detect if a view is attached or detached. In general, when is a view attached or detached? Is there a lifecycle diagram for this? To clarify, I'm looking for answers to what happens when: Activity sent to background, opaque view placed on top,...

What are the limitation in EditMode for custom views in Android?

android,android-view,android-custom-view,editmode
I know how to use the View.isInEditMode method. What I don't fully understand is when should I use it. That is, what should I prevent from running in EditMode. There are the obvious cases, where the custom view does all kind of crazy things like DB access, networking, threads etc....

Data binding: presentation model and view, 3rd party libs in Android

android,model-view-controller,android-view,android-viewbinder,presentation-model
I'm quickly realizing this is going to be an issue in Android with a lot of boilerplate and as I started refactoring my code I'm now effectively writing my own [email protected] version of data binding. I don't want to spend more time generalizing it and re-inventing the wheel. I was...

How to get the selected date from android TimeSquare library?

java,android,android-view,android-calendar,android-time-square
How to get user selected date from android TimeSquare library? I used getselectedate() but it didn't work and OnClickListener also not working with this. public class HomeActivity extends Activity { private String dateHolder; private CalendarPickerView calenderView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); calenderView = (CalendarPickerView) findViewById(R.id.calendar_view); calenderView.init(lastYear.getTime(), nextYear.getTime())...

how do i check if the edit text view contains 2 white spaces?

android,android-fragments,android-edittext,android-view,android-textview
Currently my edit text view checks if the searched term contains one space as follows: if(mSearchView.getText().toString().contains(" ") How do I make it such that it makes sure it checks if the searchview contains 2 spaces between 3 search terms for example: "here it is"...

Android, UI Element in custom View

android,android-view,ondraw
I'm getting used to creating custom views in android. One thing i wish todo is to include existing UI elements such as EditText, or Switch in my custom view. I have previously developed with Cocoa (iOS), and was able to instantiate native elements within my custom view. At onDraw(Canvas canvas)...

Decapitalizing text in Android view

android,android-view,android-textview
I want to insert a text into an Android view, like a button. The problem is that I want the capitalize some specific characters in my text, but Android capitalize all the text I in the text field. For example, I labeled a button with the text "ExaMple" in which...

how to completely hide a row from tableLayout android?

java,android,android-layout,android-view,android-tablelayout
The rows with the hours 18, 19, 20, 21 are hidden using the INVISIBLE option. But it still leaves the empty gap at the end. Is there any way to remove that gap as well? private void hideEveningHours() { // hiding evening rows TableRow tr=(TableRow)findViewById(R.id.row18); tr.setVisibility(View.INVISIBLE); tr=(TableRow)findViewById(R.id.row19); tr.setVisibility(View.INVISIBLE); tr=(TableRow)findViewById(R.id.row20); tr.setVisibility(View.INVISIBLE);...

TextView and EditText cut off in LinearLayout

android,android-layout,android-edittext,android-view,android-textview
I have a LinearLayout with horizontal orientation in which I add some TextView and EditText dynamically. My problem is when the TextView is long, it is cut off (by height) and the EditText is invisible. Adding padding to the views didn't solve it. When setting the LinearLayout minHeight value, the...

I created a custom view by subclassing SearchView. How can I reference in it XML now?

android,xml,android-view,android-custom-view
I programmatically creating a custom view by extending the AppCompat SearchView. How do I reference this class in my XML? I cannot use the fully qualified name because I am using different product flavors with gradle that have different package names. Specifically, app:actionViewClass=".views.EventSearchView" causes a ClassNotFoundException <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"...

ViewPropertyAnimator without start call, is there a difference?

android,android-animation,android-view,viewpropertyanimator
Sometimes I see code like view.animate().alpha(1).start(); And sometimes view.animate().alpha(1); What (if any) is the difference? The animation always starts but from my understanding of the source code two entirely different things happen in the background before it does so depending on the start call. ...

How to use the MultiTouchController library? (Android)

android,android-view,multi-touch
I want to manipulate a library I just discovered to drag/rotate and pinch zoom images. I am using two sources: -The library itself: MultiTouchController.java https://code.google.com/p/android-multitouch-controller/source/browse/MTController/src/org/metalev/multitouch/controller/MultiTouchController.java -An implementation of this library: PhotoSortrView https://code.google.com/p/android-multitouch-controller/source/browse/MTPhotoSortr/src/org/metalev/multitouch/photosortr/PhotoSortrView.java My issue is that I want to use this in a...

reset Android FrameLayout object to “clean” state

android,android-layout,android-view,framelayout,object-pooling
I am trying to implement my own Android view recycling. My question is, is there a simple way to "reset" an Android View object (more specifically, a FrameLayout) to the state in which it would come out of a constructor. In other words, it knows about its context, but it's...

What am I missing here - in implementing tabs in my activity?

android,android-layout,android-view,android-tabs,fragmentstatepageradapter
My MainActivity class - where I want to implement fixed tabs package com.nikhil.tabs; import android.app.ActionBar; import android.support.v4.app.FragmentTransaction; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewPager pager = (ViewPager) findViewById(R.id.pager);...

How/where can I “stash”/keep data in my application?

java,android,android-layout,android-view
I display dates to the user in a layout that are let's say are textual. When the user presses a button I want to get the information in those fields that represent these "dates" but if I get the text in them is not of value to me. I would...

Reset all Views in fragment

android,android-fragments,android-viewpager,android-view
So I am currently in FragmentA.java, a class which consists of different EditTexts and Checkboxes for users to press and input. My question is, I have this reset button, how can I reset the entire fragment view? (e.g. an EditText will be set to empty string, or with the value...

Android Custom View: getting null references on every class members in the onDraw method

java,android,nullpointerexception,android-view,ondraw
I'm trying to create a android custom view and i'm facing a rather strange problem. Every data members I set in the constructor (String, Bitmap, ...) become null in the overriden onDraw method. Here's the code: public class SimulationView extends View { private static final String TAG = "SIMULATION_VIEW"; private...

GridView, Get Item's parent View

android,android-layout,android-view,android-adapter,android-gridview
I'm trying to send clicks to my child elements in GridView with a single touch event. So far, I can retrieve the data of the child element, but cannot perform a click on it. Let me explain a bit more on the layout of things... GridView - Touch Event Handler...

android:fitsSystemWindows not working

android,android-view
In my theme I defined the following rules to draw my views behind the status bar: <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> And in the Activity (onCreate): getWindow.getDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ) Then, in my View im using a Barcodescanner that is supposed to draw behind the status bar, which is working....

Android: can you have a ripple effect whose default state color is transparent?

android,android-layout,android-view,android-selector
Something like the following, but it doesn't work. If I switch the drawable color to something like blue, it works. <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item android:drawable="@android:color/transparent"/> </ripple> ...

Difference between view.findViewById(R.id…) and just findViewById(R.id…)

android,android-view,findviewbyid
I'm trying to implement a Custom Array Adapter , Problem is my code crashes when I use ImageView imageView=(ImageView)findViewById(R.id.imageView); rather than ImageView imageView=(ImageView)rowView.findViewById(R.id.imageView); where rowView is the layout file for the ListView that i have infalted. Why does this occur , I thought rowView.findViewById(R.id..) will just make it faster to...

Android ActionBar not visible

java,android,android-layout,android-actionbar,android-view
I've updated the API 21, tools and extras up to date, the ActionBar in some projects has gone invisible. I did this following code, but app crashes showing NullPointerException. ActionBar actionBar = getActionBar(); actionBar.show(); Logcat Output 02-23 18:03:36.269: E/AndroidRuntime(3327): FATAL EXCEPTION: main 02-23 18:03:36.269: E/AndroidRuntime(3327): Process: com.example.twaapp, PID: 3327 02-23...

update Views in layout when a view changes

android,android-layout,android-linearlayout,android-view
I have a LinearLayout with 2 views. when I move the upper view at runtime the second view doesn't move accordingly and I can't seem to find a solution. can anyone help? here's the layout I'm using right now: <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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"...

Difference between an AppCompat view and a normal Android view

android,android-view,android-support-library,appcompat
What is the difference between an AppCompat view component and a standard/default view component? For example, the difference between an AppCompatEditText, and an EditText, or between an AppCompatButton and a Button. Looking at the developer docs for android.support.v7.widget, the AppCompat view components are described as "tint aware", but is this...

How to make a view from pieces aligned to each other with different behavior android

android,android-layout,animation,view,android-view
Let's say I have an animal face in pieces. I have an exterior, right ear, left ear, nose, mouse, eyes. Each of this part is independent component, so even when all of it gathered into one, animation of nose is different from ears and doesn't happen at the same time....

Possible overdraw: Root element paints background i can't resolve

android,android-fragments,android-view
hello i have this simple view: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/lavagna_verticale" android:orientation="vertical" > <TextView android:id="@+id/voto_lavagna" android:layout_width="235sp" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:gravity="center"...

OnclickListner on a custom listview adapter

android,android-listview,android-view,onclicklistener,baseadapter
I am newbie to Android so you can expect this a little silly but please do help. I have somewhat like custom listviews of people similar to whatsapp and other IM apps etc. Now when i click the listview i want to get the respective id of the clicked listview....

Android left and right alignment of listview

java,android,android-layout,android-view,android-xml
I want to align the listview left and right inside a RelativeLayout as done in IM apps. My Problem is that things are getting random. Sometimes when m.getme() == 0 then its msg_row_he.xml layout loaded but sometimes its msg_row_me.xml loaded. And the align of listview's are changing at every scroll....

How to get a list of all views in a fragment?

android,android-fragments,android-view
I would like to get a list of all views inside a main Fragment, so that I could iterate through them in a for loop. Maybe something like this: for (View v : fragmentViews) { ...

drawing sloped rectangle upper edge shape as in yahoo digest news app using xml android

android,android-layout,android-view,android-shape
am trying to draw sloped rectangle upper edge shape and use it as linear layout background as in the picture: here is the link to the design am trying to achieve: http://postimg.org/image/krjwfcisz/ I tried to draw a rectangular and rotate it but it didn't work fine. so how to create...

Changing the visibility of views one at a time with a button

java,android,android-view,android-button,android-looper
I have three views which visibility is currently set to view.setVisibility(view.GONE) and I have a button which I want to change the visibilities to visible one at a time as the user keeps clicking the button. I think I have to use a for loop centred on the button click...

android layout 50% above and below boundary

android,android-layout,android-view
I can't find words to describe my problem exactly. I was thinking about this problem few hours without any solution. Here is an image for better understating of my problem. So my viewB is below viewA. Problematic part is how to position viewC in xml so that viewA and viewB...

Design a button in Android

android,eclipse,android-layout,button,android-view
I am designing an Android activity, but it is the first one. I have some experience in XML/JAVA. I would like to create logout and read buttons like the ones in the photo. But i have no experience in doing something like this. Could someone more expert show me how...

Android line path morphing animation

android,android-animation,android-canvas,android-view
I basically have two lines, drawn by two paths on my canvas. Each one has only two points, one is supposed to remain standstill and the other one moves. I realized this simply by creating a Path and then call moveTo(x1, y1) and lineTo(x2, y2). (x1, y1) never changes during...

How to determine which View was clicked in a ListView with custom layout

android,android-view
I have a custom ListView which has a custom layout with a couple of views. Can I check in the method onItemClick() which of these views was clicked? I searched and found one explanation but it couldn't help me a lot. Here is the custom view: @Override public View getView(int...

How to select and deselect an image in android?

java,android,android-layout,android-view
I am trying to write a project. In my project I can drag an image successfully. This is the PICTURE and Here is my ViewOnTouchListener code: package com.seifi.dragtestapplication; import android.graphics.Point; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; class ViewOnTouchListener implements View.OnTouchListener { Point pushPoint, closePoint; int lastImgLeft; int lastImgTop; FrameLayout.LayoutParams viewLP;...

Android:onclick behavior

android,onclick,android-view
The syntax for triggering a function whenever a button is hit is usually android:onclick="somefunction". What I notice is that the function triggered always has a parameter (View view), yet in the syntax above I don't see any thing passed into it. Could someone explain this to me?...

Getting position of View in onCreateViewHolder

java,android,android-view,recyclerview,android-viewholder
I am using a RecyclerView with a single row layout with an ImageView and a TextView. I want to implement a OnClickListener for the View and not for seperate ViewHolder objects. How can i get the position of the view in the Adapter? Right now i'm deleting comments on click,...

How to manipulate view inside ListView items?

android,listview,android-listview,android-view
I have a ListView in which there several rows containing two buttons and a ProgressBar (Visibility:GONE) each. My purpose is to display the ProgressBar upon click on the buttons and after completing a certain set of background operations remove that row entirely. The problem here is that after removing the...

Android - ActionBar - PopupMenu - Error

java,android,android-studio,android-actionbar,android-view
I create popupMenu in ActionBar. MainActivity.java import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.view.MenuInflater; import android.widget.PopupMenu; public class MainActivity extends Activity implements PopupMenu.OnMenuItemClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu)...

Android switching focus makes keyboard disappear

android,android-view
I want to switch between two EditText views when KEYCODE_DEL button is pressed. My code works, it indeed focuses previous EditText, but when it does that, the keyboard vanishes, and cursor is located before the actual text in that EditText. To make it more vivid, when the focus switches, the...

Getting Class is not a View Error When Using a Custom Class in Layout - Android TV

android,android-layout,android-view,android-tv
I am getting the following error: android.view.InflateException: Binary XML file line #8: Class is not a View com.abcxyzradio.ActionsRow Layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/wholeView" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.abcxyzradio.ActionsRow android:id="@+id/actions_row_actions" android:layout_width="match_parent"...

Can Activity classes be made launchable only during development/debug?

android,android-activity,android-view,android-testing
A common situation I face is that I wish to test a custom View visibly on screen while it is being developed as part of a large application. I realise that unit testing exists, particularly using ActivityUnitTestCase, but as far as I understand these frameworks don't actually attach the components...

Android java make two similar for loops into one loop

java,android,for-loop,view,android-view
Im trying to merge these two for loops together so that i can use it for one fillview. Ive been trying to try for a few days but am unsure how to do this so would appreciate some help! Any help is appreciated int maxDataSetSize = Math.max(data1.size(), Math.max(data2.size(), data3.size())) ;...

What is this Android Circular View

android,user-interface,android-view
I often see this UI pattern on Android. It consists of a circle . First Google Fit uses it. Timely has the same UI pattern. And you can interact with it , change the timer. It is not part of Android standard View. What is the name of this view...

Android onTouch recognized on other view

android,android-view
I have two buttons packed into the same viewgroup - a simple linear layout, like this: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/activity_game_circle1" android:layout_width="120dp" android:layout_height="120dp" android:text="1" android:gravity="center" android:textSize="36sp" android:background="@drawable/blue_circle"/> <Button android:id="@+id/activity_game_circle2" android:layout_width="120dp" android:layout_height="120dp"...

Focus is Getting Lost on adapter.notifyArrayItemRangeChanged

android,android-activity,android-view,android-tv
In my Android TV app, the action button in the ActionsRow loses focus on adapter.notifyArrayItemRangeChanged(0, 1); call. I am using: View focusedView = getActivity().getCurrentFocus(); to get the focused view, but cannot set the focus back on after notifyArrayItemRangeChanged. The button with the focus before notifyArrayItemRangeChanged loses focus, and I can't...