I have done this before, but for the life of me I cant remember.
I'm wanting a tab with in a tab. This is my mainactivity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec Login = tabHost.newTabSpec("Login");
// setting Title and Icon for the Tab
Login.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab1));
Intent LoginIntent = new Intent(this, Tab1Activity.class);
LoginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Login.setContent(LoginIntent);
// Tab for jobs
TabHost.TabSpec Jobs = tabHost.newTabSpec("Jobs");
Jobs.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab2));
Intent JobsIntent = new Intent(this, Tab2Activity.class);
JobsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs.setContent(JobsIntent);
TabHost.TabSpec Jobs3 = tabHost.newTabSpec("Jobs3");
Jobs3.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent JobsIntent3 = new Intent(this, Tab3Activity.class);
JobsIntent3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs3.setContent(JobsIntent3);
// Adding all TabSpec to TabHost
tabHost.addTab(Login);
tabHost.addTab(Jobs);
tabHost.addTab(Jobs3);
}
This is Tab2Activity.java
public class Tab2Activity extends TabActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
/////////////////////////
TabHost tabHost2 = getTabHost();
TabHost.TabSpec Gmapped = tabHost2.newTabSpec("InnerTabs");
// setting Title and Icon for the Tab
Gmapped.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent GmappedIntent = new Intent(this, Tab3Activity.class);
GmappedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Gmapped.setContent(GmappedIntent);
tabHost2.addTab(Gmapped);
}
and Tab2.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:background="#332b2b"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<Button
android:id="#+id/veganfestival"
android:text="Aberdeen"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
<TextView
android:id="#+id/blank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Venue"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/postcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Postcode"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/Vdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/Vtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/blankagain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<Button
android:id="#+id/nav"
android:text="Take Me There"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
</LinearLayout>
</ScrollView>
I have not been developing long, but I understand I need to at TabHost to Tab2.xml, but unsure were. Could someone help out.
If you want an advice, use TabLayout instead, is more easy:
TabLayout Example
Related
I want to make a page using fragment that has a CardView. Let say I have 4 cardviews. I want the cardviews to be clickable and when clicked, they will open a new fragment with a VideoView. Can I only make one fragment that can play different video based on which cardview is clicked.
Meaning, let say, I click on cardview1, it will open a fragment with video1, then i click cardview 2, it will open from the same fragment but with video2. Is it possible to use only one fragment to have more than one videoView?
If possible how can I do that? someone please help.
this is my code
fragment_exercise.xml (fragment with cardviews)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
tools:context=".ExerciseFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical"
android:background="#FFF8DD">
<ImageView
android:id="#+id/logo2"
android:layout_width="149dp"
android:layout_height="48dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:layout_marginRight="50dp"
android:src="#drawable/logobg" />
<androidx.cardview.widget.CardView
android:id="#+id/c1"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient16"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Running"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/running" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c2"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient3"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Walking"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/walking" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c3"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="250dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient22"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Aerobics"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/aerobatic" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c4"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="250dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient13"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Yoga"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/yoga2" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c5"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="400dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient29"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Boxing"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/boxing" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c6"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="400dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient10"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Cycling"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/biking" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c7"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="550dp"
android:layout_marginLeft="50dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient24"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Dancing"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/dance" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/c8"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="550dp"
android:layout_marginLeft="220dp"
app:cardCornerRadius="26dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gradient30"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="4dp"
android:layout_marginTop="80dp"
android:fontFamily="#font/poppins"
android:text="Swimming"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="102dp"
android:layout_height="88dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="#drawable/m2" />
</androidx.cardview.widget.CardView>
</RelativeLayout>
</ScrollView>
ExerciseFragment.java
public class ExerciseFragment extends Fragment implements View.OnClickListener{
View v;
CardView cv1, cv2, cv3, cv4, cv5, cv6, cv7, cv8;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_exercise, container, false);
cv1 = (CardView) v.findViewById(R.id.c1);
cv1.setOnClickListener(this);
cv2 = (CardView) v.findViewById(R.id.c2);
cv2.setOnClickListener(this);
cv3 = (CardView) v.findViewById(R.id.c3);
cv3.setOnClickListener(this);
cv4 = (CardView) v.findViewById(R.id.c4);
cv4.setOnClickListener(this);
cv5 = (CardView) v.findViewById(R.id.c5);
cv5.setOnClickListener(this);
cv6 = (CardView) v.findViewById(R.id.c6);
cv6.setOnClickListener(this);
cv7 = (CardView) v.findViewById(R.id.c7);
cv7.setOnClickListener(this);
cv8 = (CardView) v.findViewById(R.id.c8);
cv8.setOnClickListener(this);
// Inflate the layout for this fragment
return v;
}
#Override
public void onClick(View v) {
Fragment fragment1, fragment2, fragment3, fragment4, fragment5, fragment6, fragment7, fragment8;
switch (v.getId()) {
case R.id.c1:
fragment1 = new VideoFragment();
FragmentTransaction transaction1 = getParentFragmentManager().beginTransaction();
transaction1.replace(R.id.container,fragment1);
transaction1.commit();
break;
case R.id.c2:
fragment2 = new VideoFragment();
FragmentTransaction transaction2 = getParentFragmentManager().beginTransaction();
transaction2.replace(R.id.container,fragment2);
transaction2.commit();
break;
case R.id.c3:
fragment3 = new VideoFragment();
FragmentTransaction transaction3 = getParentFragmentManager().beginTransaction();
transaction3.replace(R.id.container,fragment3);
transaction3.commit();
break;
case R.id.c4:
fragment4 = new VideoFragment();
FragmentTransaction transaction4 = getParentFragmentManager().beginTransaction();
transaction4.replace(R.id.container,fragment4);
transaction4.commit();
break;
case R.id.c5:
fragment5 = new VideoFragment();
FragmentTransaction transaction5 = getParentFragmentManager().beginTransaction();
transaction5.replace(R.id.container,fragment5);
transaction5.commit();
break;
case R.id.c6:
fragment6 = new VideoFragment();
FragmentTransaction transaction6 = getParentFragmentManager().beginTransaction();
transaction6.replace(R.id.container,fragment6);
transaction6.commit();
break;
case R.id.c7:
fragment7 = new VideoFragment();
FragmentTransaction transaction7 = getParentFragmentManager().beginTransaction();
transaction7.replace(R.id.container,fragment7);
transaction7.commit();
break;
case R.id.c8:
fragment8 = new VideoFragment();
FragmentTransaction transaction8 = getParentFragmentManager().beginTransaction();
transaction8.replace(R.id.container,fragment8);
transaction8.commit();
break;
}
}
}
fragment_video.xml (fragment with videoview)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".VideoFragment">
<VideoView
android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
</FrameLayout>
VideoFragment.java
this is what i have for now
public class VideoFragment extends Fragment {
View v;
VideoView view;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = (VideoView) v.findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(view);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/raw/boxing.mp4");
view.setMediaController(mediaController);
view.setVideoURI(uri);
view.requestFocus();
view.start();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_exercise, container, false);
return v;
}
}
this code has error at line:
MediaController mediaController = new MediaController(this);
please help, how do i make one fragment that will play different videos based on the clicked cardviews without having to make multiple fragments. Is it possible, if yes please help write the code for me. Thank you so much.
Dialog was designed by the XML layer and named layout inside it contains a collection of spinner and TextView and some buttons are called from main activity class now I want to know which one of the spinner inside the
D1 () function
I want to define the elements within the layer layout , How do I do that?
//layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="260dp"
android:layout_height="200dp"
android:orientation="vertical"
android:background="#f71717">
<LinearLayout
android:id="#+id/l_layout"
android:paddingTop="10dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:ignore="ObsoleteLayoutParam">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:text="وقت التسليم"
android:textSize="20dp"
tools:ignore="HardcodedText,SpUsage" />
<Spinner
android:id="#+id/tex"
android:layout_width="172dp"
android:paddingRight="40dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:drawSelectorOnTop="true"
android:popupBackground="#c853d7"
style="#style/spinner_style"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry,SpUsage"
android:entries="#array/day_"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/rl"
android:layout_width="250dp"
android:layout_height="129dp"
android:layout_below="#+id/l_layout"
android:background="#f71717"
android:layout_marginTop="0dp"
tools:ignore="ObsoleteLayoutParam">
<TextView
android:id="#+id/text_h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/spinner_minutes2"
android:paddingLeft="10dp"
android:text="ساعة"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/text_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/spinner_minutes2"
android:layout_alignBottom="#+id/spinner_minutes2"
android:layout_alignStart="#+id/button_holder"
android:paddingLeft="10dp"
android:text="دق"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/text_pam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:text="ص/م"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry"
android:layout_marginEnd="12dp"
android:layout_alignBaseline="#+id/spinner_minutes"
android:layout_alignBottom="#+id/spinner_minutes"
android:layout_alignEnd="#+id/spinner_minutes3" />
<Spinner
android:id="#+id/spinner_minutes"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
style="#style/spinner_style"
android:layout_alignStart="#+id/spinner_minutes2"
android:entries="#array/fruits" />
<Spinner
android:id="#+id/spinner_minutes2"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_marginStart="16dp"
style="#style/spinner_style"
android:layout_toEndOf="#+id/text_m"
android:entries="#array/fruits" />
<Spinner
android:id="#+id/spinner_minutes3"
android:layout_width="85dip"
android:layout_height="wrap_content"
style="#style/spinner_style"
android:paddingRight="20dp"
android:entries="#array/apm"
tools:ignore="RtlHardcoded,RtlSymmetry"
android:layout_alignBaseline="#+id/spinner_minutes2"
android:layout_alignBottom="#+id/spinner_minutes2"
android:layout_toEndOf="#+id/spinner_minutes" />
<TextView
android:id="#+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />
<LinearLayout
android:id="#+id/button_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:layout_marginTop="20dip">
<Button
android:id="#+id/button_set"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:text="Set"
tools:ignore="ButtonStyle,HardcodedText,RtlHardcoded" />
<Button
android:id="#+id/button_cancel"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginRight="10dip"
android:text="Cancel"
tools:ignore="ButtonOrder,ButtonStyle,HardcodedText,RtlHardcoded" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
// class: mainactivity
public class MainActivity extends AppCompatActivity {
Button buttonstartSetDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
buttonstartSetDialog.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
d1();
}});
}
public void d1(){
Dialog about_dlg = new Dialog(MainActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.layout);
about_dlg.show();
//Spinner spinner = (Spinner) findViewById(R.id.spinner);
}
}
to access to Spinner in your layout :
public void d1(){
Dialog about_dlg = new Dialog(MainActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.layout);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
about_dlg.show();
}
I have an activity which is not parent in that I want to call a fragment in that activity on click of an image view. So I have added onclickListner on my image view. I am getting toast on click of image view but the fragment is not getting called. What can be the issue?? Can anyone help please..
GoSend activity layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/LinearContainer">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginEnd="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginEnd="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/LinearLayoutAdditionalContactTo">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView18"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsTo"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:id="#+id/LinearLayoutTo">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTex"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTe"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="OR"
android:id="#+id/textView"
android:layout_gravity="center" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:background="#drawable/ic_chevron_right_black_48dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearContainer, fragment).commit();
Toast toast = Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_LONG);
toast.show();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
}
}
DetailsFragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Please help..
There is nothing in your activity layout with android:id="#+id/LinearContainer, and so FragmentManager does not have anywhere to place your DetailsFragment.
I want to call one fragment onclick of next image view. So I have put OnClickListener on image view but it is not getting called at all..
What can be the issue??
GoSend xml Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableRight="#drawable/ic_chevron_right_black_24dp"
android:layout_marginRight="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginRight="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginRight="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableRight="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginLeft="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView13"
android:layout_marginLeft="48dp"
android:hint="Input if you're not sender" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView16"
android:layout_marginLeft="48dp"
android:hint="input if you're not receiver" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1.00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView17"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView16"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_check_circle_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/pickup"
android:id="#+id/textView18"
android:layout_marginLeft="10dp"
android:layout_marginTop="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView20"
android:layout_marginLeft="20dp"
android:background="#drawable/box5"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_pac"
android:layout_marginRight="10dp"
android:hint="Items to deliver"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:clickable="true"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Calling this in GoSend Activity
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
next.setClickable(true);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
Bundle bundle = getIntent().getExtras();
if(bundle != null)
stringAddress = bundle.getString("address");
}
}
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Fragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
Please Help...
why are you using these below lines of code, please remove them and check the effect:-
android:clickable="true"
next.setClickable(true);
It's not realize to work but it works in maximum cases.
If you set the view to be clickable, then it will consume the click and not propagate it to the container.
I've set up a tab host and defined 5 tabs both in the xml file and the corresponding java class file. I added some fields for tab 1 and a test field for tab 2 but all I see in each tab is the repeated content from tab 1. Has anyone come across this before? code is pasted below.
Thanks
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspection);
TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("Part1");
tabSpec.setContent(R.id.tabPart1);
tabSpec.setIndicator("1");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part2");
tabSpec.setContent(R.id.tabPart2);
tabSpec.setIndicator("2");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part3");
tabSpec.setContent(R.id.tabPart3);
tabSpec.setIndicator("3");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part4");
tabSpec.setContent(R.id.tabPart4);
tabSpec.setIndicator("4");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part5");
tabSpec.setContent(R.id.tabPart5);
tabSpec.setIndicator("5");
tabHost.addTab(tabSpec);
}
and the xml code:
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tabPart1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Id"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Global Unique ID" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/jobNum"
android:hint="Job Number"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Required?"
android:id="#+id/req"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/material"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Material" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/shape"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Shape" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/size"
android:hint="Size (mm)"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:id="#+id/LvlCollectGp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collect Now?"
android:id="#+id/collectNow"
android:hint="Collect Now?" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collect Later?"
android:id="#+id/collectLtr" />
</RadioGroup>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/lvl"
android:hint="Level (m)"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabPart2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/test"
android:hint="Test" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabPart3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="#+id/tabPart4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="#+id/tabPart5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
try this code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspection);
TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("Part1");
tabSpec1.setContent(R.id.tabPart1);
tabSpec1.setIndicator("1");
tabHost1.addTab(tabSpec1);
TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("Part2");
tabSpec2.setContent(R.id.tabPart2);
tabSpec2.setIndicator("2");
tabHost2.addTab(tabSpec2);
TabHost.TabSpec tabSpec3 = tabHost.newTabSpec("Part3");
tabSpec3.setContent(R.id.tabPart3);
tabSpec3.setIndicator("3");
tabHost3.addTab(tabSpec3);
TabHost.TabSpec tabSpec4 = tabHost.newTabSpec("Part4");
tabSpec4.setContent(R.id.tabPart4);
tabSpec4.setIndicator("4");
tabHost4.addTab(tabSpec4);
TabHost.TabSpec tabSpec5 = tabHost.newTabSpec("Part5");
tabSpec5.setContent(R.id.tabPart5);
tabSpec5.setIndicator("5");
tabHost5.addTab(tabSpec5);
}