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>

Answers


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


Need Your Help

How To Implement ACID Transactions in Loopback

javascript transactions loopbackjs strongloop acid

We've been trying to implement ACID transactions in Loopback without success. The only examples in the documentation use the 'create' method.We've tried completely overriding the events as well as

Dereferencing 'void *' pointer when using struct

c pointers struct void-pointers dereference

I'm trying to make use of inode's i_private and store a struct with name and block number in it: