I have looked for ways to make a button/layoutchange that appears depending on the choice made by the user. It is a dice simulator so if you pick you need a 4 sided die or 6 sided die a different look will pop out. I am looking to get some directions. Should I premake them in html or java? Or should I use another approach? The decision of how many sides gets asked through an alertdialog. Thank you for any help.
If you want to change layout dynamically you can use generic View to hold the space and inflate appropriate layout into them.
http://developer.android.com/reference/android/view/LayoutInflater.html
You can place the button, that should appear in your XML-layout-file and set its visibility attribute to gone. Like so:
<Button
android:id="#+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:visibility="gone"
/>
Then you could change the visibility programmatically (for example in the OnTouchListener of another button or so).
//retrieve the button created in the xml-layout by its id
mButton= (Button) findViewById(R.id.button_1);
//change its visibility
mButton.setVisibility(View.VISIBLE);
mButton.setVisibility(View.GONE);
I hope, I could help you.
Best regards,
G_J
Related
I have this GridAdapter that shows my working GridView of at least 100+ buttons, but all of these will need to navigate to a page once clicked. I'm unsure of how to begin or if what I have is a substantial place to start. I know where I'd put an OnClick method and listener but I am unsure of how to ensure every button in the grid is heard separately since they don't have Ids. Guides online have been helpful but I'm still lost. If anyone has some advice as to how to proceed I'd be grateful. Both java files are attached but the array of images is not included in the Adapter screenshot.
Grid_Adapter
Grid_Fragment
You could add android:onClick="[method name here]" within the ImageButtons in your XML layout code, to call the code when each button is clicked. Note that this method has to be public and exist within the current activity.
As an example:
<?xml version="1.0" encoding="utf-8"?>
<!-- truncated -->
<Button android:id="#+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:onClick="buttonClickMethod1" />
<!-- truncated -->
Also note that this isn't the preferred method, and that using onClick listeners or data bindings is a better approach.
Finally, I would question your activity layout of having 100+ buttons from a user perspective - that seems very high.
I make an timetable application for android and I'm using ViewPagerIndicator as fragment. But now I've a problem, I want to get the TabPageIndicator to the center. Like this:
And I would to like to set the individual tab width and height. And set that tab to a drawable that support selected/pressed states.
I've not found it yet to solve these problems. I've try something with onPageSelected and ContextThemeWrapper but that doesn't work. (Maybe I'm not using it correctly).
Is this all possible to make or should I look to something else than ViewPagerIndicator? (An other option without ViewPagerIndicator is also welcome).
The app on the image is Untis Mobile and can be found on the PlayStore.
I've already ask the creators how they do it but they said the app isn't open source. (But I have found in the source that they do it with TwoDScrollView, but I'm not sure)
Edit:
The styling is fixed with vpiTabPageIndicatorStyle. (With help of XDA Developers!)
When I add 20 items it stays on the middle but only from item 4 to item 17, item 1, 2, 3, 18, 19, 20 are not in the middle. See:
Can I add a 3 empty items (or empty space) to ensure that the first and last items are in the middle? Something like this (from the Untis Mobile app):
(I've already tried android:paddingLeft in vpiTabPageIndicatorStyle but that doesn't work)
I know that viewPager.setCurrentItem(total/2) will set the TabPageIndicator in the middle but then it stays on the middle and I'm not able to select a other day (I call it in onPageScrolled). So I want as you scroll the selected one needs to be in the middle. Is this possible?
The widget you are looking for is similar to the android horizontal wheel. There is an implementation at android-spinnerwheel which can be what you need.
Then you don't need an viewpagerindicator. Use a horizontal scroll view as Amulya Khare suggested in your activity and replace fragments when scrolling occurs.
Your activity layout could be like :
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SomeWheelView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<SomeStaticIndicatorView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
Set a listener to wheelview and when change occurs you can put your fragments in framelayout in your activity.
Use it like this :
TabPagerIndicator tbi;
ViewPager pager;
in onCreate() do like this
tbi=(TabPagerIndicator)findViewById(R.id.something);
tbi.setViewPager(pager);
I hope this will work out for you. :D
I would like to have a EditText in my Android app that you can not see, however you can select and type text into. In other words I would like it so that it can not be seen at all however other than that it behaves completely normally.
Another option is to have an image or button on the screen which the user presses to enter text into the EditText which is hidden behind another EditText.
Thanks for the help, however it is looking more likely that I will have to use the second option. To elaborate on it, for example I have a TextView that says 'Welcome'. I would like the user to be able to click on this text to bring up the keyboard and edit in the EditText field. The reason for having the EditText field hidden behind another is to cover up the cursor while making it seem the user is typing the text which appears on the screen.
If you would like to make the EditText fully invisible (even what the user types in) , but still be able to retrieve the entered data through myEditText.getText().toString(),
you could add:
android:textColor="#android:color/transparent"
android:background="#00000000"
android:cursorVisible="false"
if I'm getting you correctly. Here is how you can accomplish the first option of yours by setting the background to transparent and cursor visibility to false.
To check this you have to click at the center of screen.
e.g. code snippet:
<EditText
android:id="#+id/eT1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#00000000"
android:cursorVisible="false"
android:ems="10" >
</EditText>
Set transparent Background to EditText.
android:background="#00000000"
Sorry but I didn't understand your another question.
OK the header says it.
I want to be able to create my own controls such as buttons, textviews, edittext boxes, spinners, and so on. I can create the images in CS5 but how do I turn those images into functional GUI components? Thanks
You mean you want to create a custom looking version of those controls right?
You could make an ImageButton component for any custom button you made, and use the attribute android:src, like
android:src="#drawable/your_image"
Similarly for EditText you can use the attribute android:background.
Edit:
The android controls are not stored as standard image files anywhere accessible. The standard designs that you mentioned are the default look of the elements.
To change it, you would have to create the background yourself and store it as a .png file in the drawable folder of your project. Make sure you name this file only in lower case and with no special characters like spaces etc.. Copy this file into all the drawable folders(drawable-hdpi,ldpi etc).
Then you have to refer to this file within your box as
<EditText
android:background="#drawable/your_edit_text_graphic_file_name"
android:text="#string/sample_text"
android:layout_width="match_parent"
-- all other attribute declarations --
</EditText>
Similarly, for other elements you would have to use android:src like is mentioned earlier to refer to your own graphic!
Hope this helps!
You just create your CustomView extend View or TextView.... and implement event handle. Android Developer had a training about this Custom Components . When you finish you can find your custom view in GraphicLayout => CustomView in Eclipse and add like normal components.
Images just provide nice appearance not event handle so you can not just make image to component
You don't have to use CSS in case of android you have to use XML file for UI designing.You can create UI in XML statically or dynamically(i.e. Programmatically). You can create button in android in the following manner.
<Button
android:id="#+id/buttonStart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your btn Name"/>
You can access this button in your java file by getting id of button and use it.
Hope this helps.
For more info read this post http://developer.android.com/reference/android/widget/Button.html
My app tracks how players at a pokertable play. I give my users the option to save up to 50 players stats in the form of a 'Player' object stored inside a JSON array within sharedPreferences. Allowing the user a way of selecting and loading one of these players has proven difficult.
An alertDialog seems to small, a new activity seems a bit overboard for what is essentially just a large menu and I fear passing my objects to it will prove difficult. A viewFlipper sounds interesting but I've no idea whether it's suitable.
How should I go about doing this? Filling the screen with dozens of buttons is really all I wish to do.
I agree that creating a new activity for this would be an overkill. One way to address this would be to have a GridView populated with your "buttons" - and the user would select one from the grid by clicking it. The question is where/how to display this grid.
ViewFlipper is a nice option in my opinion. The way you would go about it is place your existing layout inside the view flipper, then put the GridView into the ViewFlipper after your existing layout:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/flipper">
<LinearLayout ...>
<!-- this is where your main layout goes -->
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/player_select"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
Then in your activity set up the Adapter for your grid view and the OnItemClickListener - to do something when one item is clicked. Finally somewhere (either in the main layout or in the options menu or elsewhere) provide something to display this grid view. In the handler code for that action you'd have something like
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showNext();
This would effectively hide your main layout and show the grid instead. And at the end of your OnItemClickListener you'll have
ViewFlipper flip = (ViewFlipper)flip.findViewById(R.id.flipper);
flip.showPrevious();
This would hide the grid view and navigate back to your main layout. Feel free to add any animation you like for the transition (e.g. 3G flip animation looks particularly nice).
Try an AutoCompleteTextView. Start typing one of the names, and a list of all possible matches pops up.
Screenshot from Google's tutorial:
I went with a ListView. It combines the filtering and tidyness of the autocomplete yet displays the names so users don't have to remember them like the ViewFlipper solution.
Thanks for both answers, they are both good solutions that helped me come to the solution I needed which combines the two.
The autocomplete had the advantage of searching so I could extend the number of players a user can save to my hearts content, it also looked neat but could not easily see the whole list which for poker players was necessary as the names you give when titling your notes are rarely your fellow players name but rather off the cuff nicknames based on their appearance/playing style. Hence using autocomplete the user will have to remember the nicknames they gave which over 50 players and potentially months apart would prove tricky.
Alek Gs solution would avoid that problem but would not be suited large numbers of names or long names for that matter as the buttons would be off fixed sizes.