I want to "remake" my app.
I already write an app and it works OK. But, it use Activity and Spinner to switch between screens - that is too uncomfortable and slow.
I here find an example of Fragment usage for user-comfortable usage and fast switching beetween screens with swiping:
http://www.theappguruz.com/blog/android-tab-layout-with-swipeable-views
But I cant set RelativeLayout for it from my app, because it use Fragment.
Is there a way to "copy-paste" the markup file (*.xml) without making fundamental changes in the application?
I tried to do it (the commented line of code), but it does not work.
FirstTab.java
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class FirstTab extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/*View view=inflater.inflate(R.layout.tab_first, container, false);
Button imageView = (Button) getView().findViewById(R.id.btn_quit);
return view;*/
TextView tv = new TextView(getActivity());
tv.setText("First Tab");
tv.setGravity(Gravity.CENTER);
tv.setTextColor(Color.WHITE);
tv.setWidth(LayoutParams.MATCH_PARENT);
tv.setHeight(LayoutParams.MATCH_PARENT);
tv.setBackgroundColor(Color.RED);
tv.setTextAppearance(getActivity(),android.R.style.TextAppearance_Large);
return tv;
}
}
first_tab.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingBottom="5sp"
android:paddingTop="5sp"
android:paddingRight="5sp"
android:paddingLeft="5sp"
android:background="#color/colorPrimary">
<Spinner
android:entries="#array/activity_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:layout_alignRight="#+id/view1"
android:layout_alignEnd="#+id/view1"
android:layout_toRightOf="#+id/btn_quit"
android:layout_toEndOf="#+id/btn_quit"
android:layout_alignBottom="#+id/btn_quit"
android:layout_alignParentTop="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close\napp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/btn_quit"
android:onClick="quit"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#android:color/holo_orange_light"
android:id="#+id/view1"
android:layout_below="#+id/btn_quit"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/eng_text"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#android:color/white"
android:hint="Enter text"
android:minLines="1"
android:layout_below="#+id/view1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
android:maxLines="7"/>
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#android:color/holo_orange_light"
android:id="#+id/view"
android:layout_below="#+id/eng_text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/morse_text"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#android:color/white"
android:hint="Get a code"
android:minLines="1"
android:layout_below="#+id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
android:maxLines="8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Translate"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/trans_btn"
android:layout_above="#+id/btn_sound"
android:layout_centerHorizontal="true"
android:layout_alignParentRight="true"
android:onClick="translate"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|bottom"
android:text="Play\ncode:"
android:id="#+id/play_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/trans_btn"
android:layout_toLeftOf="#+id/btn_sound"
android:layout_toStartOf="#+id/btn_sound" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_sound"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/btn_flash"
android:layout_toStartOf="#+id/btn_flash"
android:padding="2dp"
android:onClick="play_sound"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_flash"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/view"
android:layout_alignEnd="#+id/view"
android:padding="2dp"
android:onClick="play_flash"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Current input\nlanguage:"
android:id="#+id/cur_lang"
android:layout_alignTop="#+id/trans_btn"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btn_flag"
android:layout_alignTop="#+id/cur_lang"
android:layout_toRightOf="#+id/cur_lang"
android:layout_toEndOf="#+id/cur_lang"
android:enabled="false"/>
</RelativeLayout>
You want to convert your whole three activities to fit into a single page using view pager
Make a new Activity with root tag a android.supprot.v4.ViewPager
Set up the adapter and all the other things
In your first tab use the following code
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.tab_first, container, false);
Button button = (Button)view.findViewById(R.id.btn_quit);
button.setText("Working quit");
return view;
}
use view to access any of the elements of first_tab
Related
I have an activity and when I click on the "Register" TextView a fragment will open and in that fragment all the Registration detail is there.But when I click on the textview the Fragment is loaded successfully but it did'nt cover up the entire screen.
Here is my code:
MainActivity.java
Register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.support.v4.app.FragmentManager fragmentManager=getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
Fragments fragments=new Fragments();
fragmentTransaction.replace(R.id.Fragment_Register,fragments);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
}
});
}
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.attendance.MainActivity"
android:background="#drawable/blurbackgound"
android:padding="10dp"
android:focusableInTouchMode="true"
>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="WELCOME"
android:textColor="#color/white"
android:textStyle="bold"
android:fontFamily="monospace"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:id="#+id/login_mobile_number"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:background="#drawable/edit_text_border"
android:padding="15dp"
android:textColor="#color/white"
android:inputType="number"
android:hint="Enter mobile number"
android:gravity="center"
android:maxLength="10"
android:textColorHint="#color/hint_color"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_local_phone_black_24dp"
android:layout_below="#id/title"
android:layout_marginLeft="30dp"
android:layout_marginTop="73dp"
android:id="#+id/phonelogo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mb_counter"
android:layout_below="#id/title"
android:layout_marginLeft="300dp"
android:layout_alignBaseline="#id/login_mobile_number"
android:text="abssh"
android:textColor="#color/white"
/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/login_mobile_number"
android:layout_marginTop="25dp"
android:background="#drawable/edit_text_border"
android:paddingRight="50dp"
android:hint="Password"
android:gravity="center"
android:textColorHint="#color/hint_color"
android:inputType="textPassword"
android:textColor="#color/white"
android:id="#+id/login_password"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="1dp"
android:layout_below="#id/login_password"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/white"
android:text="Student"
android:textColor="#color/white"
android:id="#+id/Radio_button_student"
android:layout_marginLeft="19dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:buttonTint="#color/white"
android:text="Teacher"
android:textColor="#color/white"
android:id="#+id/Radio_button_teacher"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SHOW"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_alignRight="#id/login_password"
android:layout_alignBaseline="#id/login_password"
android:id="#+id/password_visibility"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_lock_outline_black_50dp"
android:layout_marginLeft="30dp"
android:layout_below="#id/phonelogo"
android:layout_marginTop="39dp"
/>
<Button
android:stateListAnimator="#null"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Login"
android:id="#+id/login"
android:background="#drawable/login_buttom"
android:textColorHint="#color/hint_color"
android:layout_below="#id/login_password"
android:layout_marginTop="50dp"
android:layout_marginLeft="35dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FORGOT PASSWORD"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginTop="18dp"
android:layout_marginLeft="48dp"
android:id="#+id/forgot_password"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="#color/white"
android:layout_alignBaseline="#id/forgot_password"
android:layout_marginLeft="170dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTER"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginLeft="185dp"
android:layout_marginTop="20dp"
android:id="#+id/Register"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/Fragment_Register"></RelativeLayout>
</RelativeLayout>
Fragments.java
package com.example.user.attendance;
import android.app.FragmentManager;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import de.hdodenhof.circleimageview.CircleImageView;
public class Fragments extends Fragment {
Button Register_Cancel_fullname, Register_Cancel_email, Register_Cancel_phone,
Register_Cancel_password, Sign_up,Register_Cancel_Confirm_Password;
String Passcode,Confirm_Passcode;
EditText Full_Name, Email_Address, Phone_number, Password_register,Confirm_Password_register;
CircleImageView Register_add_photo;
LinearLayout select_photo_from_camera,select_photo_from_gallery;
TextView textView,hint_textview_circular_image_view;
// RadioButton Category_teacher,Category_student;
RadioGroup Teacher_student;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View myfragmentVieew = inflater.inflate(R.layout.fragment_signup, container, false);
//Edit Text
Full_Name = (EditText) myfragmentVieew.findViewById(R.id.Register_name_and_surname);
Email_Address = (EditText) myfragmentVieew.findViewById(R.id.Register_Email_address);
Phone_number = (EditText) myfragmentVieew.findViewById(R.id.Register_Phone);
Password_register = (EditText) myfragmentVieew.findViewById(R.id.Register_Password);
Confirm_Password_register=(EditText)myfragmentVieew.findViewById(R.id
.Confirm_Password_Register);
//Button
Sign_up = (Button) myfragmentVieew.findViewById(R.id.Register_Signup);
Register_Cancel_fullname = (Button) myfragmentVieew.findViewById(R.id.Register_First_Cancel_Button);
Register_Cancel_email = (Button) myfragmentVieew.findViewById(R.id.Register_Second_Cancel_Button);
Register_Cancel_phone = (Button) myfragmentVieew.findViewById(R.id.Register_Third_Cancel_Button);
Register_Cancel_password = (Button) myfragmentVieew.findViewById(R.id.Register_fourth_Cancel_Button);
Register_Cancel_Confirm_Password=(Button)myfragmentVieew.findViewById(R.id
.Register_Cancel_Confirm_Password_Button);
Register_add_photo=(CircleImageView)myfragmentVieew.findViewById(R.id.Register_add_photo);
//TextView
textView = (TextView) myfragmentVieew.findViewById(R.id.Register_textview);
hint_textview_circular_image_view=(TextView)myfragmentVieew.findViewById(R.id
.hint_of_image_view);
return myfragmentVieew;
}
}
Here is what I am getting:
Remove this line from root layout.
android:padding="10dp"
This will solve the problem.
HI I'm making GymExercises App and every Exercise is written in different Fragment
so i want to add Video to show how exercise to do,it compiles but doesn't show anything can someone help me ?
PS i don't need play,stop button and anything other just to show the video
Here is the code that i add
Example:
BenchFragment.java
package com.Hristijan.Aleksandar.GymAssistant.Exercises;
import android.media.session.MediaController;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;
import java.net.URL;
/**
* A simple {#link Fragment} subclass.
*/
public class BenchFragment extends Fragment {
public BenchFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_bench, container, false);
VideoView view = (VideoView)rootView.findViewById(R.id.video_view);
String path = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench1;
view.setVideoURI(Uri.parse(path));
view.start();
return inflater.inflate(R.layout.fragment_bench, container, false);
}
}
fragment_bench.xml
<RelativeLayout 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"
android:background="#000000"
tools:context="com.Hristijan.Aleksandar.GymAssistant.Exercises.BenchFragment">
<VideoView
android:id="#+id/video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
/>
<TableLayout
android:layout_marginTop="20dp"
android:layout_below="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*">
<TableRow>
<TextView
android:text="#string/group"
android:background="#color/colorPrimary"
android:layout_width="500dp"
android:textColor="#ffffff"
android:textStyle="italic"
android:fontFamily="Arial"
android:textSize="17sp"
android:padding="5dip" />
</TableRow>
<TableRow>
<TextView
android:text="#string/bencbody"
android:textStyle="italic"
android:fontFamily="Arial"
android:textSize="17sp"
android:textColor="#ffffff"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:text="#string/description"
android:textStyle="italic"
android:fontFamily="Arial"
android:textSize="19sp"
android:background="#color/colorPrimary"
android:textColor="#ffffff"
android:padding="5dip" />
</TableRow>
<TableRow>
<TextView
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fontFamily="Arial"
android:gravity="left"
android:layout_marginTop="5dp"
android:text="#string/stepone"
android:textColor="#android:color/white"
android:textSize="15sp"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fontFamily="Arial"
android:layout_marginTop="5dp"
android:gravity="left"
android:text="#string/steptwo"
android:textColor="#android:color/white"
android:textSize="16sp"
android:padding="3dip" />
</TableRow>
</TableLayout>
</RelativeLayout>
In an Activity I have some textviews which includes multi-line and long-messages, the textviews also have vertical scroll in them, these text views also have long-click-listener on them. Now the problem is that when I click on any of the textviews it gives me paste option and it also pastes the text on it (if I click paste). I have tried to set android:editable="false" but it does not work. So Please help.
XML Code:
<?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"
android:overScrollMode="never"
android:scrollbars="none"
android:id="#+id/helpActivityScroll_id">
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.appdeveloper.appname.HelpActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpAppImage_id"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:src="#drawable/app"
android:layout_marginTop="20dp"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpAppText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpAppImage_id"
android:layout_alignBottom="#+id/helpAppImage_id"
android:layout_toEndOf="#+id/helpAppImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpAppText_id"
android:id="#+id/helpAppPeopleSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpTrustedPeopleImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/trusted"
android:layout_below="#+id/helpAppPeopleSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpTrustedPeopleText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpTrustedPeopleImage_id"
android:layout_toEndOf="#+id/helpTrustedPeopleImage_id"
android:layout_alignBottom="#+id/helpTrustedPeopleImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpTrustedPeopleText_id"
android:id="#+id/helpPeopleRingSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpRingImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/ring"
android:layout_below="#+id/helpPeopleRingSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpRingText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpRingImage_id"
android:layout_toEndOf="#+id/helpRingImage_id"
android:layout_alignBottom="#+id/helpRingImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentEnd="true"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpRingText_id"
android:id="#+id/helpRingLocationSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpLocationImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/location"
android:layout_below="#+id/helpRingLocationSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpLocationText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpLocationImage_id"
android:layout_toEndOf="#+id/helpLocationImage_id"
android:layout_alignBottom="#+id/helpLocationImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpLocationText_id"
android:id="#+id/helpLocationPictureSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpPictureImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/picture"
android:layout_below="#+id/helpLocationPictureSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpPictureText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/helpPictureImage_id"
android:layout_toEndOf="#+id/helpPictureImage_id"
android:layout_alignBottom="#+id/helpPictureImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpPictureText_id"
android:id="#+id/helpPictureSimSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpSimImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/sim"
android:layout_below="#+id/helpPictureSimSeparator_id"
android:layout_marginLeft="5dp"
android:layout_marginBottom="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpSimText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/helpSimImage_id"
android:layout_toEndOf="#+id/helpSimImage_id"
android:layout_alignBottom="#+id/helpSimImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical"/>
</RelativeLayout>
</ScrollView>
JAVA Code:
package com.example.appdeveloper.appname;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
public class HelpActivity extends AppCompatActivity implements View.OnLongClickListener, View.OnTouchListener {
private ScrollView helpActivityScrollView;
private TextView helpApp;
private TextView helpTrustedPeople;
private TextView helpRing;
private TextView helpLocation;
private TextView helpPicture;
private TextView helpSim;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff003b")));
actionBar.setTitle("Help");
helpActivityScrollView = ((ScrollView)findViewById(R.id.helpActivityScroll_id));
helpActivityScrollView.setOnTouchListener(this);
helpApp = (TextView)findViewById(R.id.helpAppText_id);
helpApp.setMovementMethod(new ScrollingMovementMethod());
helpApp.setOnLongClickListener(this);
helpTrustedPeople = (TextView)findViewById(R.id.helpTrustedPeopleText_id);
helpTrustedPeople.setMovementMethod(new ScrollingMovementMethod());
helpTrustedPeople.setOnLongClickListener(this);
helpRing = (TextView)findViewById(R.id.helpRingText_id);
helpRing.setMovementMethod(new ScrollingMovementMethod());
helpRing.setOnLongClickListener(this);
helpLocation = (TextView)findViewById(R.id.helpLocationText_id);
helpLocation.setMovementMethod(new ScrollingMovementMethod());
helpLocation.setOnLongClickListener(this);
helpPicture = (TextView)findViewById(R.id.helpPictureText_id);
helpPicture.setMovementMethod(new ScrollingMovementMethod());
helpPicture.setOnLongClickListener(this);
helpSim = (TextView)findViewById(R.id.helpSimText_id);
helpSim.setMovementMethod(new ScrollingMovementMethod());
helpSim.setOnLongClickListener(this);
String appHelp = "log and multi line message 1";
helpApp.setText(appHelp);
String trustedPeopleHelp = "log and multi line message 2";
helpTrustedPeople.setText(trustedPeopleHelp);
String ringHelp = "log and multi line message 3";
helpRing.setText(ringHelp);
String locationHelp = "log and multi line message 4";
helpLocation.setText(locationHelp);
String pictureHelp = "log and multi line message 5";
helpPicture.setText(pictureHelp);
String simHelp = "log and multi line message 6";
helpSim.setText(simHelp);
}
#Override
public boolean onLongClick(View view) {
view.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
helpActivityScrollView.requestDisallowInterceptTouchEvent(false);
return false;
}
}
Add empty click listener for it which override default behaviour of textView. same thing you can apply for other textview like below :
helpSim.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
Hope these solve your problem.
I'm working on an app where I am supposed to fragment my MainActivity into 2 fragments. One on the right whitch going to hold some textEdits and buttons, and one on the left that should hold some sliding tabs.
I already did the fragmentation part, and added tabs on the left fragment, but the problem is I don't know how to make the tabs slide. Please I really need your help. Thanks in advance.
This is what I wrote so far:
MainActivity=>AppActivity.java:
package com.example.g514110.morphokitihm1;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AppActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_container_1, new MainTab())
.commit();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_container_2, new StaticFragment())
.commit();
}
}
public static class MainTab extends Fragment {
private FragmentTabHost mTabHost;
//Mandatory Constructor
public MainTab() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main_tab,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmenta").setIndicator("Biometric operations"),
Tab1.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("DataBase operations"),
Tab2.class, null);
return rootView;
}
}
public static class Tab1 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1, container, false);
return rootView;
}
}
public static class Tab2 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab2, container, false);
return rootView;
}
}
public static class StaticFragment extends Fragment {
private View rootView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.activity_static_frag, container, false);
return rootView;
}
}
}
activity_app.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent">
<FrameLayout
android:id="#+id/main_container_1"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="450dp"/>
<FrameLayout
android:id="#+id/main_container_2"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="200dp"/>
</LinearLayout>
</LinearLayout>
activity_static_frag.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Acquisition pannel-->
<RelativeLayout
android:layout_width="170dp"
android:layout_height="fill_parent"
android:background="#drawable/textview_border"
android:orientation="vertical"
android:id="#+id/relativeLayout3"
android:layout_marginLeft="68dp"
android:layout_marginStart="71dp"
android:layout_below="#+id/APLabel">
<VideoView
android:layout_width="150dp"
android:layout_height="160dp"
android:id="#+id/videoView"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:text="#string/Sacqu"
android:id="#+id/stop"
android:background="#drawable/shutdown_design"
android:src="#drawable/shutdown1"
android:layout_column="4"
android:layout_marginTop="170dp"
android:layout_marginLeft="130dp" />
<TextView
android:layout_width="150dp"
android:layout_height="27dp"
android:text=" "
android:id="#+id/msg"
android:background="#DFDFDF"
android:layout_below="#+id/videoView"
android:layout_alignRight="#+id/videoView"
android:layout_alignEnd="#+id/videoView"
android:layout_marginTop="35dp"/>
<TextView
android:layout_width="150dp"
android:layout_height="27dp"
android:text=" "
android:background="#DFDFDF"
android:id="#+id/qty"
android:layout_below="#+id/msg"
android:layout_alignLeft="#+id/msg"
android:layout_alignStart="#+id/msg"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="#+id/qtyProgressbar"
android:layout_width="150dp"
android:layout_height="20dp"
android:background="#DFDFDF"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
android:layout_below="#+id/qty"
android:layout_alignLeft="#+id/qty"
android:layout_alignStart="#+id/qty"
android:layout_marginTop="20dp"/>
</RelativeLayout>
<TextView
android:id="#+id/APLabel"
android:layout_width="106dp"
android:layout_height="15dp"
android:background="#drawable/textview_border"
android:text="#string/AP"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="100dp"
android:layout_marginTop="10dp"/>
</RelativeLayout>
activity_main_tab.xml:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_detail_container">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/realtabcontent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
tab1.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_detail_container">
<!--Enrollement settings-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/textview_border"
android:orientation="vertical"
android:id="#+id/linearLayout4"
android:layout_marginTop="80dp"
android:layout_marginLeft="0dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="#string/consolidation"
android:id="#+id/cons_ch"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="#string/SI"
android:id="#+id/save_img_ch"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="#string/SDB"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/FFOT"
android:id="#+id/frc_ch"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ST"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:id="#+id/save_temp_ch"/>
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="#string/enroll"
android:id="#+id/enroll"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:background="#drawable/designed_buttons"/>
</LinearLayout>
<TextView
android:id="#+id/APLabel"
android:layout_width="106dp"
android:layout_height="15dp"
android:background="#drawable/textview_border"
android:text="#string/ES"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="65dp" />
<RelativeLayout
android:layout_width="300dp"
android:layout_height="110dp"
android:background="#drawable/textview_border"
android:orientation="horizontal"
android:id="#+id/linearLayout6"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp"
android:layout_alignTop="#+id/linearLayout4"
android:layout_toRightOf="#+id/linearLayout4"
android:layout_toEndOf="#+id/linearLayout4">
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="#string/verif"
android:id="#+id/verif"
android:onClick="verify"
android:layout_marginTop="10dp"
android:layout_marginLeft="180dp"
android:background="#drawable/designed_buttons"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="#string/identify"
android:id="#+id/identify"
android:onClick="identify"
android:layout_marginTop="5dp"
android:background="#drawable/designed_buttons"
android:layout_gravity="center_horizontal"
android:layout_below="#+id/verif"
android:layout_alignLeft="#+id/verif"
android:layout_alignStart="#+id/verif" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/matchingIcon"
android:background="#drawable/matching"
android:layout_marginLeft="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<TextView
android:id="#+id/MOASLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/textview_border"
android:text="#string/MOAS"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_above="#+id/linearLayout6"
android:layout_alignLeft="#+id/linearLayout6"
android:layout_alignStart="#+id/linearLayout6" />
</RelativeLayout>
tab2.xml:
<?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"
android:id="#+id/item_detail_container">
<!--Database operations-->
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/storageIcon"
android:background="#drawable/stor1"
android:layout_marginTop="30dp"
android:layout_marginLeft="5dp"
android:layout_alignBottom="#+id/record"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/textview_border"
android:id="#+id/linearLayout5">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/CreatMatch"
android:background="#drawable/designed_buttons"
android:id="#+id/matcher"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NewRecord"
android:id="#+id/record"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="#string/RecordList"
android:id="#+id/record_list"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="#string/dbsize"
android:id="#+id/dbSize"
android:textColor="#000"
android:layout_span="2"
android:layout_above="#+id/db_size"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/db_size"
android:background="#DFDFDF"
android:layout_span="6"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
I want to use a few Button, Spinner and TextView on fragmets but i don't know how to do that since i was newbie in android programming.
I'd appreciate any help! Thanks a lot!
here's my java activity
package com.elvis.triagetags;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class formActivity extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.form, container, false);
return rootView;
}
}
and this my form.layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="428dp"
android:orientation="vertical"
android:padding="15dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/header"
android:textSize="25sp" />
<TextView
android:id="#+id/fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/fullname"
android:textColor="#0000CD"
android:textSize="21sp" />
<EditText
android:id="#+id/etIden"
android:layout_width="284dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:textSize="21sp" />
<TextView
android:id="#+id/Gen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/gen"
android:textColor="#0000CD"
android:textSize="21sp" />
<Spinner
android:id="#+id/spinGen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/btn_dropdown" />
<TextView
android:id="#+id/tvdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/date"
android:textColor="#0000CD"
android:textSize="21sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etdate"
android:layout_width="0.99dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="date" >
</EditText>
<Button
android:id="#+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/wp_button"
android:text="#string/date1" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="148dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginTop="25dp"
android:layout_weight="0.87"
android:contentDescription="#string/pop"
android:src="#drawable/no_image" />
<TextView
android:id="#+id/imageDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/urlImage"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="italic"
android:typeface="serif" />
<Button
android:id="#+id/capture_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/wp_button"
android:text="#string/capture" />
<Button
android:id="#+id/next_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="25dp"
android:background="#drawable/wp_button"
android:text="#string/bt" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#000000"
android:gravity="center" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/elvis"
android:textColor="#ffffff"
android:textSize="16sp" />
</RelativeLayout>
This is a small example to show you how to do:
package com.elvis.triagetags;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Spinner;
public class formActivity extends Fragment {
Button btnDate;
Button btnCapture;
Spinner spinGen;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.form, container, false);
btnCapture = (Button) rootView.findViewById(R.id.capture_button);
btnDate = (Button) rootView.findViewById(R.id.btnDate);
spinGen = (Spinner) rootView.findViewById(R.id.spinGen);
spinGen.setOnItemSelectedListener(new SpinnerGen());
btnDate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//...
}
});
//...
return rootView;
}
}
public class SpinnerGen implements OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
//...
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
// TODO Auto-generated method stub
}
follow this link, you will find a good example