android-view

Android: How to test a custom view?

牧云@^-^@ 提交于 2020-01-11 18:03:12
问题 There are several methods of unit testing in Android, what's the best one for testing a custom view I've written? I'm currently testing it as part of my activity in an instrumentation test case, but I'd rather test just the view, isolated. 回答1: Well unit testing is a method by which individual units of source code are tested to determine if they are fit for use. So when you say you want to test your custom view, you can check various methods of your custom views like "onTouchEvent", "onDown",

Finding the View location (position) on display (screen) in android

♀尐吖头ヾ 提交于 2020-01-10 03:50:12
问题 I want to find the view's position on the display screen. To do it, I use the methods such as view.getLeft() , view.getBottom() , view.getRight() , view.getTop() . But unfortunately, all these methods are returned 0 . Is there any alternate way to find the view's positions (i.e coordinates on screen)? My layout main.xml : <TextView android:id="@+id/tv1" android:layout_width="200px" android:layout_height="30px" android:text="welcome to" /> <TextView android:id="@+id/tv2" android:layout_width=

Android onInterceptTouchEvent, get childs in ViewGroup

大憨熊 提交于 2020-01-06 06:40:31
问题 I have a layout(like board) like this that contains cells(buttons) | A | B | C | D | ----------------- | E | F | G | H | ----------------- | I | J | K | L | ----------------- | X | Y | Z | W | I'm adding Cells programmatically, they contains letters I set. public void addCells(String letters){ removeAllViews(); int let = 0; for (int j = 0; j < 4; j++){ for (int i = 0; i < 4; i++){ String currentLetter = ""+letters.charAt(let); //Cell object that contains it's position and letter. Cell cell_ =

How to get a ListView's child view at specific index

风流意气都作罢 提交于 2020-01-05 13:32:32
问题 I need to dynamically change the background color of a child view of a ListView at a specific index. So I need to get the view first before applying the background. I have tried the following. getViewAt(int index) - this is not applicable to ListView . getChildAt(int index) - this gives runtime NPE error A Google search returns irrelevant results. Please help me out. Thank you. 回答1: I figured out how to do this. I really think that one should not have to post code and logcat for a question

ImageView setVisibility(0) and null pointer exception

坚强是说给别人听的谎言 提交于 2020-01-05 09:05:25
问题 I have 2 xml files, a main file where I have a listView and the other where I am making some customisations to my listView . The second xml is used on my Custom ArrayAdapter . In the second xml i have a ImageView which I would like to set to visible at one moment but I am getting the null pointer exception because i am never setting with setCurrentView the second xml file where is my ImageView . I am trying to do this: ImageView statusOk=(ImageView)findViewById(R.id.statusOkImage); statusOk

ImageView setVisibility(0) and null pointer exception

大城市里の小女人 提交于 2020-01-05 09:05:08
问题 I have 2 xml files, a main file where I have a listView and the other where I am making some customisations to my listView . The second xml is used on my Custom ArrayAdapter . In the second xml i have a ImageView which I would like to set to visible at one moment but I am getting the null pointer exception because i am never setting with setCurrentView the second xml file where is my ImageView . I am trying to do this: ImageView statusOk=(ImageView)findViewById(R.id.statusOkImage); statusOk

Android: How to create a custom notification and edit its layout adding views programmatically?

假装没事ソ 提交于 2020-01-04 06:46:22
问题 I'd like to know how to create a custom notification and edit is layout adding views programmatically to allow user to customize is notification. What I can't do is this: If I create a custom LinearLayout like this: LinearLayout ll = new LinearLayout(c); ImageView iv = new ImageView(c); iv.setImageResource(R.drawable.bt_close); ll.addView(iv); How I can create a notification using this layout and add an action to do when I click on ImageView? The code to make a custom notification is only

Android: How to create a custom notification and edit its layout adding views programmatically?

房东的猫 提交于 2020-01-04 06:46:07
问题 I'd like to know how to create a custom notification and edit is layout adding views programmatically to allow user to customize is notification. What I can't do is this: If I create a custom LinearLayout like this: LinearLayout ll = new LinearLayout(c); ImageView iv = new ImageView(c); iv.setImageResource(R.drawable.bt_close); ll.addView(iv); How I can create a notification using this layout and add an action to do when I click on ImageView? The code to make a custom notification is only

Place view on top and between two views

别说谁变了你拦得住时间么 提交于 2020-01-04 05:24:26
问题 Trying to figure out to overcome this little problem. Below, on the left side, is a sample of the view that I'm trying to implement for an app. On the right side is the view that I'm ending up with. In my xml mock up I've decided to use a RelativeLayout but I can't get the TextView to be centered between the top and bottom views. For reference here's a represenation of my xml code: <RelativeLayout android:layout_width:"match_parent" android:layout_height:"wrap_content"> <ImageView android:id=

How do I make my full-screen overlay remain full-screen after orientation changes?

笑着哭i 提交于 2020-01-04 02:28:29
问题 I am making an app that creates tiny sprite animations that walk around your screen. I have a main activity, with a button "start service". This starts a service, which (in onCreate() ) creates a full-screen view and attaches it to the root window manager. This part works perfectly. It fills the screen, and you can leave the app, and the animations will still be visible over everything. The problem emerges when you rotate the device. Sprites have moved to the middle of the screen, but this is