Joehamir Joehamir - 25 days ago 6
Android Question

How to do login and register with php and mysql in fragment?

how to do login and register with php and mysql in fragment?
I need sample code.. hope someone can help me..

here is my loginfragment code..

Package com.example.administrator.mosbeau;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by Administrator on 9/1/2015.
*/
public class LoginFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.loginlayout, container, false);
}
}


and here is my loginlayout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:fillViewport="false">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/logo"
android:maxHeight="54dp"
android:maxWidth="322dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView5"
android:layout_below="@+id/imageView4"
android:layout_centerHorizontal="true"
android:src="@drawable/lock"
android:layout_marginLeft="150dp"
android:layout_marginRight="150dp"
android:layout_marginTop="-60dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtEmail"
android:layout_below="@+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:hint="Email"
android:background="#ffeeeeee"
android:padding="10dp"
android:layout_marginTop="-30dp"
android:textColor="#ff6d6e71" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/txtPassword"
android:layout_below="@+id/txtEmail"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:textColor="#ff6d6e71"
android:background="#ffeeeeee"
android:padding="10dp"
android:hint="Password" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in"
android:id="@+id/btnSignin"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textColor="#ff6d6e71"
android:layout_marginTop="10dp"
android:layout_below="@+id/txtPassword"
android:longClickable="false"
android:clickable="true"
android:background="#fffed4d4" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot your Password ?"
android:id="@+id/textForgot"
android:layout_below="@+id/btnSignin"
android:layout_alignLeft="@+id/btnSignin"
android:layout_marginTop="10dp"
android:textColor="#ff607d8b"
android:textSize="18dp"
android:clickable="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
android:id="@+id/textSignup"
android:layout_alignBottom="@+id/textForgot"
android:layout_alignRight="@+id/btnSignin"
android:textColor="#ff607d8b"
android:textSize="18dp"
android:layout_marginTop="10dp"
android:clickable="true" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login with facebook"
android:id="@+id/btnLoginfb"
android:layout_below="@+id/textForgot"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:layout_marginRight="30dp"
android:background="#ff2385ff"
android:textColor="#ffffffff"
android:clickable="true"
android:focusableInTouchMode="false" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Help"
android:id="@+id/btnLoginhelp"
android:layout_below="@+id/btnLoginfb"
android:layout_alignLeft="@+id/btnLoginfb"
android:layout_marginTop="10dp"
android:background="#fffed4d4"
android:textColor="#ff6d6e71"
android:clickable="true"
android:layout_marginBottom="20dp"
android:focusableInTouchMode="false" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Skip"
android:id="@+id/btnLoginskip"
android:background="#fffed4d4"
android:textColor="#ff6d6e71"
android:layout_alignTop="@+id/btnLoginhelp"
android:layout_alignRight="@+id/btnLoginfb"
android:clickable="true"
android:layout_marginBottom="20dp"
android:focusableInTouchMode="false" />

</RelativeLayout>
</ScrollView>


I'm new to android so i really dont know how to do that..
i already develop login and register with php and mysql by following tutorials..
but it use activity..

N J N J
Answer

Here is good example for the

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Overall steps to do :

  1. Create Web-service for login in PHP
  2. Call that Web-service form android Fragment
  3. Get response and parse it
  4. Show the Result to User

see this link for working with Fragments

Comments