Hello Guys , I am going to give you some easy example code of php. Like login and registration. Find the demo project here:-
Home file
htaccess
front
Complete zip
Android dynamic
edittext
Dynamic Edit text
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
public class AddUser extends AppCompatActivity {
private LinearLayout layout;
List<EditText> allEds = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_add_user);
final Button addField = (Button) findViewById(R.id.add_views);
Button done = (Button) findViewById(R.id.done);
layout = (LinearLayout) findViewById(R.id.layout);
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
;
switchActivity(getValues());
}
});
addField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addFields();
}
});
}
private void switchActivity(ArrayList<String> values) {
Intent intent =new Intent(AddUser.this,AllUser.class);
intent.putStringArrayListExtra("usersData",values);
startActivity(intent);
}
private ArrayList<String> getValues() {
int size = allEds.size();
String[] names = new String[size];
ArrayList<String> fullName = new ArrayList<>();
String oneName = null;
for (int i = 0; i < allEds.size(); i++) {
names[i] = allEds.get(i).getText().toString();
if (i / 2 != 0) {
oneName = oneName + " "+names[i];
fullName.add(oneName);
oneName="";
Log.d("value", oneName);
}else{
oneName=names[i];
}
}
return fullName;
}
private void addFields() {
for (int i = 0; i < 2; i++) {
LinearLayout ll = new LinearLayout(AddUser.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);
ll.setLayoutParams(layoutParams);
// ll.setLayoutParams(new LinearLayout.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));
// ll.set
ll.setOrientation(LinearLayout.VERTICAL);
EditText name = new EditText(AddUser.this);
allEds.add(name);
name.setBackgroundResource(R.color.edittext_background);
name.setId(name.generateViewId());
// name.setLayoutParams(new ActionBar.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.WRAP_CONTENT));
ll.addView(name);
layout.addView(ll);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_user, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Add it into list
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
/**
* Created by gwl on 25/2/16.
*/
public class AllUser extends Activity {
private ListView userList;
private ArrayList<String> fetchList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_user);
userList= (ListView) findViewById(R.id.user_list);
fetchList= getIntent().getStringArrayListExtra("list");
ArrayAdapter<String> itemsAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fetchList);
userList.setAdapter(itemsAdapter);
}
}
Home file
htaccess
front
Complete zip
Android dynamic
edittext
Dynamic Edit text
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
public class AddUser extends AppCompatActivity {
private LinearLayout layout;
List<EditText> allEds = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_add_user);
final Button addField = (Button) findViewById(R.id.add_views);
Button done = (Button) findViewById(R.id.done);
layout = (LinearLayout) findViewById(R.id.layout);
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
;
switchActivity(getValues());
}
});
addField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addFields();
}
});
}
private void switchActivity(ArrayList<String> values) {
Intent intent =new Intent(AddUser.this,AllUser.class);
intent.putStringArrayListExtra("usersData",values);
startActivity(intent);
}
private ArrayList<String> getValues() {
int size = allEds.size();
String[] names = new String[size];
ArrayList<String> fullName = new ArrayList<>();
String oneName = null;
for (int i = 0; i < allEds.size(); i++) {
names[i] = allEds.get(i).getText().toString();
if (i / 2 != 0) {
oneName = oneName + " "+names[i];
fullName.add(oneName);
oneName="";
Log.d("value", oneName);
}else{
oneName=names[i];
}
}
return fullName;
}
private void addFields() {
for (int i = 0; i < 2; i++) {
LinearLayout ll = new LinearLayout(AddUser.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);
ll.setLayoutParams(layoutParams);
// ll.setLayoutParams(new LinearLayout.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT));
// ll.set
ll.setOrientation(LinearLayout.VERTICAL);
EditText name = new EditText(AddUser.this);
allEds.add(name);
name.setBackgroundResource(R.color.edittext_background);
name.setId(name.generateViewId());
// name.setLayoutParams(new ActionBar.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.WRAP_CONTENT));
ll.addView(name);
layout.addView(ll);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_user, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Add it into list
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
/**
* Created by gwl on 25/2/16.
*/
public class AllUser extends Activity {
private ListView userList;
private ArrayList<String> fetchList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_user);
userList= (ListView) findViewById(R.id.user_list);
fetchList= getIntent().getStringArrayListExtra("list");
ArrayAdapter<String> itemsAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fetchList);
userList.setAdapter(itemsAdapter);
}
}