Modifying Image View Dynamically on a button click inside a fragment - android

package com.example.layout.layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.HashMap;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.View.OnClickListener;
import org.w3c.dom.Text;
/**
* A placeholder fragment containing a simple view.
*/
public class MovieInfoFile extends Fragment {
public static final String ARG_OPTION="argument_option";
HashMap[]items=new HashMap[30];
int i;
public ImageView image;
TextView name;
TextView des;
TextView stars;
TextView year;
TextView rating;
public static MovieInfoFile newInstance(int option)
{
MovieInfoFile fragment=new MovieInfoFile();
Bundle args=new Bundle();
args.putInt(ARG_OPTION,option);
fragment.setArguments(args);
return fragment;
}
public MovieInfoFile() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.movieinfolayout, container, false);
Button loadnext=(Button) view.findViewById(R.id.next);
image=(ImageView) view.findViewById((R.id.image1));
name=(TextView) view.findViewById(R.id.nameans);
des=(TextView) view.findViewById(R.id.desans);
stars=(TextView) view.findViewById(R.id.starans);
year=(TextView) view.findViewById(R.id.yearans);
rating=(TextView) view.findViewById(R.id.ratingans);
enter code hereView.OnClickListener aButtonChangeImageListener=new OnClickListener() {
#Override
public void onClick(View v) {
if(v.getId()==R.id.next)
{
int id=(Integer)items[1].get("image");
image.setImageResource(id);
}
}
};
return view;
}
}
Here is the layout (XML file)
<?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:layout_gravity="center"
android:background="#drawable/baground"
android:weightSum="1">
<ImageView
android:layout_width="315dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="#drawable/avatar"
android:id="#+id/image1"
android:layout_weight="0.53" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"
android:id="#+id/table1">
<TableRow>
<TextView
android:text="Movie Name: "
android:textStyle="bold"
android:id="#+id/name"
/>
<TextView
android:text="Movie Name: "
android:textStyle="bold"
android:id="#+id/nameans"
/>
</TableRow>
<TableRow>
<TextView
android:text="Description: "
android:textStyle="bold"
android:id="#+id/des"
/>
<TextView
android:text="Description: "
android:textStyle="bold"
android:id="#+id/desans"
/>
</TableRow>
<TableRow>
<TextView
android:text="Stars "
android:textStyle="bold"
android:id="#+id/star"
/>
<TextView
android:text="Stars "
android:textStyle="bold"
android:id="#+id/starans"
/>
</TableRow>
<TableRow>
<TextView
android:text="Year"
android:textStyle="bold"
android:id="#+id/year"
/>
<TextView
android:text="Year"
android:textStyle="bold"
android:id="#+id/yearans"
/>
</TableRow>
<TableRow>
<TextView
android:text="Rating"
android:textStyle="bold"
android:id="#+id/rating"
/>
<TextView
android:text="Rating"
android:textStyle="bold"
android:id="#+id/ratingans"
/>
</TableRow>
</TableLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LoadPrev"
android:id="#+id/prev"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loadnext"
android:layout_gravity="center_horizontal"
android:id="#+id/next"/>
</LinearLayout>
I am trying to change the image view dynamically on a button click inside a fragment. But when i do this, it is giving me error, "Unfortunately your app has stopped".Can any one help me in this and tell me the right way of modifying views dynamically on a button click with in a fragment.

for the button load next(i guess after clicking this image should change), So pass aButtonChangeImageListener to the Button loadNext like this:
loadNext.setOnClickListener(aButtonChangeImageListener);
before return view line

Related

click related keyword like a search input

Hi sorry for my bad title (i really dont know how to phrase it better) but i have a cardview just like this cardview where the result/s returned are based on the user has input on the search bar.
All of the information returned are based on my database (DB Browser for SQLite). the cardview itself is not clickable but now I want the related keyword section to be clickable in a way where if a user click on one of the related keywords, it will open the cardview of that keyword like the same way when if the user search on it. (pardon me for my bad english!) As of now I only know that I have to add the clickable=true on the UI. However, logic-wise, I am not sure.
Below are my codes:
Cardview UI
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="8dp">
<LinearLayout
android:orientation="vertical"
android:layout_weight="9"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/keyword"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="15dp"
android:text="Baggage Management Interface Device (BMID) Testing
123"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/acronym"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textStyle="italic"
android:textColor="#a8000000"
android:text="GST"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/description"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="If none are set then 'GST' is set to NULL"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/relatedKeyword"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="Related Keyword:"
android:textSize="12sp"
android:textStyle="bold|italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/relatedKeyword1"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 1"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/relatedKeyword2"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 2"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/relatedKeyword3"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 3"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Search Adapter + SearchView Holder
package com.example.run_h.boav2.Adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.run_h.boav2.Model.Knowledge;
import com.example.run_h.boav2.R;
import java.util.List;
class SearchViewHolder extends RecyclerView.ViewHolder{
public TextView keyword, description, acronym, relatedkeyword1,
relatedkeyword2, relatedkeyword3;
public SearchViewHolder(#NonNull View itemView) {
super(itemView);
keyword = itemView.findViewById(R.id.keyword);
acronym = itemView.findViewById(R.id.acronym);
description = itemView.findViewById(R.id.description);
relatedkeyword1= itemView.findViewById(R.id.relatedKeyword1);
relatedkeyword2= itemView.findViewById(R.id.relatedKeyword2);
relatedkeyword3= itemView.findViewById(R.id.relatedKeyword3);
}
}
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder>
{
private Context context;
private List<Knowledge> knowledge;
public SearchAdapter(Context context, List<Knowledge> knowledge) {
this.context = context;
this.knowledge = knowledge;
}
#NonNull
#Override
public SearchViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int
viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.layout_item, parent,
false);
return new SearchViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull SearchViewHolder holder, int position)
{
holder.keyword.setText(knowledge.get(position).getKeyword());
holder.description.setText(knowledge.get(position).getDescription());
holder.acronym.setText(knowledge.get(position).getAcronym());
holder.relatedkeyword1.setText(knowledge.get(position).getRelatedkeyword1());
holder.relatedkeyword2.setText(knowledge.get(position).getRelatedkeyword2());
holder.relatedkeyword3.setText(knowledge.get(position).getRelatedkeyword3());
}
#Override
public int getItemCount() {
return knowledge.size();
}
}
Anyone knows how I can implement this? Much appreciated. Thanks!

Video doesn't play in fragment

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>

Android - Change RelativeLayout to Fragment

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

android <merge /> can be used only with a valid viewgroup root and attachtoroot=true

I am trying to inflate a fragment xml that does not have merge anywhere in it. Yet I am being given the error stated in the question.
My fragment class :
package com.xxxxx.www.xxxxxx;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ExcercisePlanFragment extends Fragment
{
public static ExcercisePlanFragment newInstance()
{
ExcercisePlanFragment fragment = new ExcercisePlanFragment();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_excercise_plan, container, false);
}
}
Here is fragment_excercise_plan.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_bg"
android:orientation="vertical">
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
android:layout_width="wrap_content"
android:layout_height="44dp"
android:minWidth="88dp"
android:background="#color/mediumGray"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:layout_centerInParent="true"
android:textColor="#FFF"
android:textSize="14sp"
android:text="CREATE A PLAN"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#FFF"
android:textSize="20sp"
android:text="OR" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
android:layout_width="wrap_content"
android:layout_height="44dp"
android:minWidth="88dp"
android:background="#color/mediumGray"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:layout_centerInParent="true"
android:textColor="#FFF"
android:textSize="14sp"
android:text="CHOOSE A PLAN"/>
</RelativeLayout>
</LinearLayout>
I have no idea where build.gradle is picking up merge. I have another fragment activity which is working perfectly.

use few button and other widget in Fragments

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

Categories

Resources