I am wondering how to change selecting view in TimePicker. For example: I am at minute view and click some button and view change to selecting hour.
.
I am using custom Timepicker class with TimePicker in layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
style="#style/AppTheme"
android:background="#color/colorPrimaryDark">
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tp_timepicker"
android:layout_weight="1" />
</LinearLayout>
Since requesting focus on the text views of the time picker didn't work, I went with performing the click on them - worked for me!
TimePicker tp = parentView.findViewById(R.id.tp_timepicker)
View timePickerPart = tp.findViewById(Resources.getSystem().getIdentifier("hours", "id", "android"));
timePickerPart.performClick();
Also works for minutes instead of hours. May work for amPm, too.
Related
I need to enter an initial date and a final date similar to this application in IOs:
Gif video about IOs app
I'm thinking of using a DatePicker to enter the initial date and then another or the same for the final date.
But my boss wants to see both DatePicker at the same time for the start date and end date. Is that possible?
Or there is a way to do something similar to the video gif previously indicated.
Thanks
You could you use 2 datepickers like this below,
<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"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></DatePicker>
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</DatePicker>
</LinearLayout>
</ScrollView>
</LinearLayout>
I have a problem with the date picker in android 6.0 Marshmallow.
The problem is a simple one, in landscape mode, i have the OK button missing.
Here are some images to demonstrate the problem. (It works perfectly with the time picker)
The problem on tablet and phone:
As you can see, i have a spinner on top, but removing it didn't help.
I dont have that problem on the system itself.Here on setting and set datetime it works fine:
Here is the layout for the date time fragment.
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:orientation="vertical">
<Spinner
android:id="#+id/spinner_date_time_choice"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Spinner>
<TimePicker
android:id="#+id/time_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<DatePicker
android:id="#+id/date_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I have made a customised navigational drawer with 3 buttons and I want to change text on the buttons according to the activity they are associated with. So when I made a java object of the layout of navigational drawer using LayoutInflater and got handle of each button using findViewById on that layout object, I set Text of each button but when i am running the app the text does not appear(in XML I have not set any text for the buttons). Rest all is working fine.
<FrameLayout 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"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sahil.childcare.NavigationalDrawerFragment">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<include
layout="#layout/nav_profile"
android:id="#+id/nav_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/nav_profile"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-5dip"
android:layout_marginBottom="-5dip"
android:id="#+id/top_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-7dip"
android:layout_marginBottom="-5dip"
android:id="#+id/middle_button" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/middle_button"
android:id="#+id/bottom_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="-5dip"
android:layout_marginRight="-5dip"
android:layout_marginTop="-7dip"
android:layout_marginBottom="-5dip"/>
</RelativeLayout>
</FrameLayout>
The part of the code in main activity(inside onCreate() method) involving this drawer is here
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.fragment_navigational_drawer,null);
Button topButton = (Button) view.findViewById(R.id.top_button);
Button middleButton = (Button) view.findViewById(R.id.middle_button);
Button bottomButton = (Button) view.findViewById(R.id.bottom_button);
topButton.setText("School");
topButton.setTextColor(getResources().getColor(R.color.red));
middleButton.setText("Teacher");
middleButton.setTextColor(getResources().getColor(R.color.red));
bottomButton.setText("Child");
bottomButton.setTextColor(getResources().getColor(R.color.red));
First thing I'd check if the buttons are even visible on screen.
To do that you can set them some color background, e.g.:
android:background="#ff0000"
and also use hierarchy-viewer to make sure your buttons appear where you expect them to appear.
Next thing to check is if the newly inflated fragment_navigational_drawer is actually being used for the Navigation Drawer, or maybe it's a different instance of this layout, to do that you can add some logging to the inflation code, printing the specific instance you put on screen, and verifying in hierarchy-viewer you see the right instance on screen.
UPDATE:
For completeness of the answer, per comments below, if you already added a layout via xml (e.g. using <include>), instead of inflating it in code:
View view = inflater.inflate(R.layout.fragment_navigational_drawer,null);
you need to get a handle of the already inflated layout, via something like:
View view = findViewById(R.id.my_navigational_drawer);
I'm building an application using CalendarView. My issue is, that I don't find the way to customize the calendar style.
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/calendario_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CalendarView
android:id="#+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
When I show this screen, I get the month's name and the year, like in the photo.
How can I customize the CalendarView style?
for designing the calendar you can try this Link
and change the
android:layout_height="wrap_content"
to
android:layout_height="match_parent"
this might also help you Link
My main.xml layout simply contains two buttons and a content area, which shows below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/myBtns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/btn_one"
android:layout_width="100dip"
android:layout_height="30dip"
android:text="button one"
/>
<Button
android:id="#+id/btn_two"
android:layout_width="100dip"
android:layout_height="30dip"
android:text="button two"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/content_area"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<!--different button press will embed different content here-->
</LinearLayout>
</LinearLayout>
I would like to create my own tab-like feature that each button press will update the content(the content_area) below the buttons. So I have prepared two other content layout:
content_one.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView.../>
<Button .../>
</LinearLayout>
content_two.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Gallery.../>
<Button .../>
</LinearLayout>
With all my simple codes showed above, I would like to implement the feature that:
in main.xml:
when button_one is pressed, content_one.xml will be embeded to the content_area of main.xml;
when button_two is pressed, the content_area of main.xml will be updated to content_two.xml
Which means using button to create a tab-like feature.
I tried:
button_one.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(R.layout.content_one, null);
LinearLayout contentArea= (LinearLayout) findViewById(R.id.content_area);
contentArea.addView(inflatedView);
}
});
button_two.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(R.layout.content_two, null);
LinearLayout contentArea= (LinearLayout) findViewById(R.id.content_area);
contentArea.addView(inflatedView);
}
});
The above code is partly working, what I mean is that when button_one is pressed, the content_area shows content_one.xml , or when button_two is pressed, the content_area shows content_two.xml , they are working fine!
But if either button is pressed firstly, then press the other one, the content remains in the old button triggered content. For example, when application first loaded, if firstly press button_one, content_one.xml is showing, after that , if I press button_two, the content is remain in content_one.xml.
My Question is how to remove the old content and show the new content when using LayoutInflater?
The problem is you're not removing the old view when adding the new one. Stick this line of code before you add the new view:
contentArea.removeAllViews()
Edit: Note that inflating the view every time the button is pressed, your previous state will always be lost. If you need to keep the state of the view I would go with Idistic's suggestion.
What others have done is simply hide one layout and then show the other
Stackoverlow how to change layouts dynamically
It's not exactly what you are asking but accomplishes the same thing