forked from hussien89aa/AndroidTutorialForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fragment.txt
77 lines (58 loc) · 1.92 KB
/
Fragment.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tp1" />
<Button
android:text="Done"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buDome" />
</LinearLayout>
//Fragment class
package com.hussienalrubaye.androiddemowork;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TimePicker;
/**
* Created by hussienalrubaye on 9/7/16.
*/
public class PopTime extends DialogFragment implements View.OnClickListener {
View view;
TimePicker tp;
Button buDome;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
view=inflater.inflate(R.layout.pop_time,container,false);
tp=(TimePicker)view.findViewById(R.id.tp1);
buDome=(Button)view.findViewById(R.id.buDome);
buDome.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
this.dismiss();
String timeOn=tp.getHour() +":"+ tp.getMinute();
MainActivity ma=(MainActivity)getActivity();
ma.SetTime(timeOn);
}
}
/display Fragment from Activity
public void SetTime(String Time){
Toast.makeText(getApplicationContext(),Time,Toast.LENGTH_LONG).show();
}
public void bushow(View view) {
android.app.FragmentManager fm= getFragmentManager();
PopTime popTime=new PopTime();
popTime.show(fm,"Show fragment");
}