Advertisement
Guest User

example of my task system with login and register

a guest
Sep 1st, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.07 KB | None | 0 0
  1. MainActivity.java
  2. ========================
  3. package com.example.zeevm.mysharedpref;
  4.  
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.support.v7.app.AlertDialog;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18.  
  19.     EditText txtUserName;
  20.     EditText txtUserPass;
  21.     TextView lblMsg;
  22.     Context context;
  23.  
  24.     private int totalTry=5;
  25.     Button btnLogin;
  26.     Button btnRegister;
  27.  
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);
  32.         setPointer();
  33.     }
  34.  
  35.     private void setPointer()
  36.     {
  37.         this.context=this;
  38.         txtUserName=(EditText)findViewById(R.id.txtUserName);
  39.         txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
  40.         lblMsg=(TextView)findViewById(R.id.lblMsg);
  41.         btnLogin=(Button)findViewById(R.id.btnLogin);
  42.         btnRegister=(Button)findViewById(R.id.btnRegister);
  43.  
  44.         //listerners
  45.         btnLogin.setOnClickListener(new View.OnClickListener() {
  46.             @Override
  47.             public void onClick(View view) {
  48.                login();
  49.             }
  50.         });
  51.  
  52.         btnRegister.setOnClickListener(new View.OnClickListener() {
  53.             @Override
  54.             public void onClick(View view) {
  55.                 register();
  56.             }
  57.         });
  58.     }
  59.  
  60.     private void login()
  61.     {
  62.         String getUser=txtUserName.getText().toString();
  63.         String getPass=txtUserPass.getText().toString();
  64.  
  65.         if (totalTry==0) {
  66.             Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
  67.             return;
  68.         }
  69.         utlShared shared = new utlShared(this);
  70.         if (shared.checkUserPassword(getUser,getPass))
  71.         {
  72.             Intent intent = new Intent(this,Welcome.class);
  73.             intent.putExtra("userName",getUser);
  74.             startActivity(intent);
  75.             finish();
  76.         }
  77.         else {
  78.             if (shared.checkUser(getUser))
  79.             {
  80.                 Toast.makeText(context, "Wrong password", Toast.LENGTH_SHORT).show();
  81.             }
  82.             else {
  83.                 showLoginErrorDialog();
  84.             }
  85.             //Toast.makeText(MainActivity.this, "Wrong user name or password", Toast.LENGTH_SHORT).show();
  86.  
  87.         }
  88.     }
  89.  
  90.     private void register()
  91.     {
  92.         startActivity(new Intent(this,Register.class));
  93.     }
  94.  
  95.     private void showLoginErrorDialog()
  96.     {
  97.         new AlertDialog.Builder(this)
  98.                 //set title to dialog
  99.                 .setTitle("User not found")
  100.                 //set message to dialog
  101.                 .setMessage("Do you want to register new user")
  102.                 //set ok(yes) button
  103.                 .setPositiveButton("register", new DialogInterface.OnClickListener() {
  104.                     @Override
  105.                     public void onClick(DialogInterface dialogInterface, int i) {
  106.                         //close the dialog
  107.                         dialogInterface.dismiss();
  108.                         //start register activity
  109.                         startActivity(new Intent(context,Register.class));
  110.  
  111.                     }
  112.                 })
  113.                 //set cancel(no) button
  114.                 .setNegativeButton("let me try again", new DialogInterface.OnClickListener() {
  115.                     @Override
  116.                     public void onClick(DialogInterface dialogInterface, int i) {
  117.                         dialogInterface.dismiss();
  118.                     }
  119.                 })
  120.                 //show the dialog
  121.                 .show();
  122.     }
  123.  
  124. }
  125.  
  126.  
  127. Register.java
  128. ==============
  129. package com.example.zeevm.mysharedpref;
  130.  
  131. import android.content.Context;
  132. import android.support.v7.app.AppCompatActivity;
  133. import android.os.Bundle;
  134. import android.view.View;
  135. import android.widget.Button;
  136. import android.widget.EditText;
  137. import android.widget.Toast;
  138.  
  139. public class Register extends AppCompatActivity {
  140.  
  141.     Button btnCancel;
  142.     Button btnRegister;
  143.     Context context;
  144.     EditText txtUser,txtPass,txtPass2;
  145.  
  146.     @Override
  147.     protected void onCreate(Bundle savedInstanceState) {
  148.         super.onCreate(savedInstanceState);
  149.         setContentView(R.layout.activity_register);
  150.         setPointer();
  151.     }
  152.  
  153.     private void setPointer()
  154.     {
  155.         this.context=this;
  156.         txtUser=(EditText)findViewById(R.id.txtUserName);
  157.         txtPass=(EditText)findViewById(R.id.txtPassword);
  158.         txtPass2=(EditText)findViewById(R.id.txtPassword2);
  159.         btnCancel=(Button)findViewById(R.id.btnCancel);
  160.         btnCancel.setOnClickListener(new View.OnClickListener() {
  161.             @Override
  162.             public void onClick(View view) {
  163.                 finish();
  164.             }
  165.         });
  166.  
  167.  
  168.  
  169.         btnRegister=(Button)findViewById(R.id.btnRegisterUser);
  170.         btnRegister.setOnClickListener(new View.OnClickListener() {
  171.             @Override
  172.             public void onClick(View view) {
  173.                 //check if password equal
  174.                 String pass1=txtPass.getText().toString();
  175.                 String pass2=txtPass2.getText().toString();
  176.                 if (!pass1.equals(pass2))
  177.                 {
  178.                     Toast.makeText(context, "Password not match!!!", Toast.LENGTH_SHORT).show();
  179.                     return;
  180.                 }
  181.                 //calling the utl shared class
  182.                 utlShared myShared = new utlShared(context);
  183.                 //check if user exists
  184.                 String userName=txtUser.getText().toString();
  185.                 if (myShared.checkUser(userName))
  186.                 {
  187.                     Toast.makeText(context, "User Exists....", Toast.LENGTH_SHORT).show();
  188.                     return;
  189.                 }
  190.                 //running the method of add user
  191.                 myShared.addUser(userName,pass1);
  192.                 finish();
  193.             }
  194.         });
  195.     }
  196.  
  197. }
  198.  
  199.  
  200.  
  201. TaskAdapter.java
  202. =================
  203. package com.example.zeevm.mysharedpref;
  204.  
  205. import android.content.Context;
  206. import android.content.SharedPreferences;
  207. import android.view.LayoutInflater;
  208. import android.view.View;
  209. import android.view.ViewGroup;
  210. import android.widget.BaseAdapter;
  211. import android.widget.Switch;
  212. import android.widget.TextView;
  213. import android.widget.Toast;
  214.  
  215. import java.util.ArrayList;
  216. import java.util.List;
  217. import java.util.Map;
  218.  
  219. /**
  220.  * Created by zeevm on 9/1/2016.
  221.  */
  222. public class TaskAdapter extends BaseAdapter {
  223.  
  224.     //transfer context
  225.     Context context;
  226.     //transfer user to use for shared preferences
  227.     String userName;
  228.     //create a list of tasks.....
  229.     List<taskItem> myTasks;
  230.  
  231.     //constructor, for creating the adapter we need from the user context and userName
  232.     public TaskAdapter(Context context,String userName) {
  233.         this.context = context;
  234.         this.userName=userName;
  235.         //go to user shared preferences and fill the list
  236.         getData();
  237.     }
  238.  
  239.     //how many item to display
  240.     @Override
  241.     public int getCount() {
  242.         //return the myTasks size....
  243.         return myTasks.size();
  244.     }
  245.  
  246.     //return a specific item by index
  247.     @Override
  248.     public Object getItem(int i) {
  249.         return myTasks.get(i);
  250.     }
  251.  
  252.     //return index number
  253.     @Override
  254.     public long getItemId(int i) {
  255.         return 0;
  256.     }
  257.  
  258.     //create our view
  259.     @Override
  260.     public View getView(int index, View view, ViewGroup viewGroup) {
  261.         //inflate the view inside view object -> viewInflated
  262.         View viewInflated = LayoutInflater.from(context).inflate(R.layout.task_item,null,false);
  263.  
  264.         //set our inflated view behiver
  265.  
  266.         //set pointer for our inflated view
  267.  
  268.         //set pointer for task name....
  269.         final TextView txtTaskName=(TextView)viewInflated.findViewById(R.id.taskName);
  270.         //set pointer for task status....
  271.         final Switch swTask=(Switch)viewInflated.findViewById(R.id.taskDone);
  272.  
  273.         //set task name, by the index of my myTasks collection
  274.         txtTaskName.setText(myTasks.get(index).taskName);
  275.         //set task status , switch is getting true/false
  276.         swTask.setChecked(myTasks.get(index).taskStatus);
  277.  
  278.  
  279.         //create listener event, when switch is pressed
  280.         swTask.setOnClickListener(new View.OnClickListener() {
  281.             @Override
  282.             public void onClick(View view) {
  283.                 //we using utlShared to update task status
  284.                 //create instance of utlShared
  285.                 utlShared myShared = new utlShared(context);
  286.                 //calling method of task, and giving userName(shared preferences, taskName, taskStatus)
  287.                 myShared.task(userName,txtTaskName.getText().toString(),swTask.isChecked());
  288.                 //we sending a message to the user, and inform him/her about the change
  289.                 Toast.makeText(context, swTask.isChecked()?"Task done...":"Task undone...", Toast.LENGTH_SHORT).show();
  290.             }
  291.         });
  292.  
  293.         //return the view with the behiver.....
  294.         return viewInflated;
  295.     }
  296.  
  297.     private void getData()
  298.     {
  299.         //go to specific shared preferences by user name.....
  300.         SharedPreferences taskPref=context.getSharedPreferences(userName,context.MODE_PRIVATE);
  301.  
  302.         //create instance of our myTasks list
  303.         myTasks = new ArrayList<>();
  304.         //get all tasks from shared preferances
  305.         //the shared preferences is by key and value, therefor we will use Map collection
  306.         //we know that the key is String, but we don't know what type of value we will get. <K,?>
  307.         Map<String,?> tasks=taskPref.getAll();
  308.         // transfer the data from map collection to list collection , single item is like the defination of the tasks <String,?>
  309.         //Entry -> record , enterSet -> set of records
  310.         for(Map.Entry<String,?> singleTask:tasks.entrySet())
  311.         {
  312.             //insert task to list by Key and Value, we check if value is equal to 1, becuase 1=true 0=false
  313.             myTasks.add(new taskItem(singleTask.getKey(),singleTask.getValue().equals("1")));
  314.         }
  315.     }
  316.  
  317. }
  318.  
  319.  
  320.  
  321. taskItem.java
  322. ==================
  323. package com.example.zeevm.mysharedpref;
  324.  
  325. /**
  326.  * Created by zeevm on 9/1/2016.
  327.  */
  328. public class taskItem {
  329.     public String taskName;
  330.     public boolean taskStatus;
  331.  
  332.     public taskItem(String taskName, boolean taskStatus) {
  333.         this.taskName = taskName;
  334.         this.taskStatus = taskStatus;
  335.     }
  336. }
  337.  
  338.  
  339.  
  340. utlShared.java
  341. ====================
  342. package com.example.zeevm.mysharedpref;
  343.  
  344. import android.content.Context;
  345. import android.content.SharedPreferences;
  346. import android.util.Log;
  347.  
  348. /**
  349.  * Created by zeevm on 8/25/2016.
  350.  */
  351. public class utlShared {
  352.     //context to use later
  353.     Context context;
  354.     //declatrtion of shared preferences object
  355.     private SharedPreferences userPref;
  356.     //declaration of shared preferences editor
  357.     private SharedPreferences.Editor editor;
  358.  
  359.     public utlShared() {}
  360.  
  361.     public utlShared(Context context)
  362.     {
  363.         //get context to use it
  364.         this.context=context;
  365.         //declaretion of shared preferences with file name and file mode (private,public)
  366.         userPref=context.getSharedPreferences("users",Context.MODE_PRIVATE);
  367.         //declaration of editor
  368.         editor=userPref.edit();
  369.     }
  370.  
  371.     //get user and password
  372.     public void addUser(String userName, String password)
  373.     {
  374.         //stores in the phone device under data\data\package name
  375.         //put in shared preferences user name and password
  376.         editor.putString(userName,password);
  377.         //commit (save/apply) the changes.
  378.         editor.commit();
  379.     }
  380.  
  381.     public boolean checkUser(String userName)
  382.     {
  383.         //get name by key->userName
  384.         String checkString = userPref.getString(userName,"na");
  385.  
  386.         //print to logcat a custom message.....
  387.         Log.e("checkUser", "checkUser: "+checkString );
  388.         //check if userName equals to responded data, if it's na, we don't havce the user...
  389.         return !checkString.equals("na");
  390.     }
  391.  
  392.     public boolean checkUserPassword(String userName, String userPassword)
  393.     {
  394.         String checkString = userPref.getString(userName,"na");
  395.         return checkString.equals(userPassword);
  396.     }
  397.  
  398.     public void task(String userName,String taskName,boolean taskDone)
  399.     {
  400.         //pointer to user task shared preferances
  401.         SharedPreferences taskPref=context.getSharedPreferences(userName,Context.MODE_PRIVATE);
  402.         //create editor to change the specific shared preferences
  403.         SharedPreferences.Editor taskEditor=taskPref.edit();
  404.  
  405.         //add new task -> if true write 1 else write 0
  406.         taskEditor.putString(taskName,taskDone?"1":"0");
  407.         //apply the changes
  408.         taskEditor.commit();
  409.     }
  410.  
  411.  
  412. }
  413.  
  414.  
  415.  
  416. Welcome.java
  417. ===================
  418. package com.example.zeevm.mysharedpref;
  419.  
  420. import android.content.Context;
  421. import android.content.DialogInterface;
  422. import android.support.v7.app.AlertDialog;
  423. import android.support.v7.app.AppCompatActivity;
  424. import android.os.Bundle;
  425. import android.text.InputType;
  426. import android.view.LayoutInflater;
  427. import android.view.View;
  428. import android.widget.EditText;
  429. import android.widget.ListView;
  430. import android.widget.Toast;
  431.  
  432. public class Welcome extends AppCompatActivity {
  433.  
  434.     String userName;
  435.     Context context;
  436.     utlShared myUtl;
  437.     ListView taskList;
  438.     @Override
  439.     protected void onCreate(Bundle savedInstanceState) {
  440.         super.onCreate(savedInstanceState);
  441.         setContentView(R.layout.activity_welcome);
  442.         setPointer();
  443.  
  444.     }
  445.  
  446.     private void setPointer()
  447.     {
  448.         this.context=this;
  449.         userName=getIntent().getStringExtra("userName");
  450.         myUtl = new utlShared(context);
  451.         taskList=(ListView)findViewById(R.id.taskList);
  452.         setListData();
  453.         Toast.makeText(Welcome.this, "welcome user:"+userName, Toast.LENGTH_SHORT).show();
  454.     }
  455.  
  456.     private void setListData()
  457.     {
  458.         TaskAdapter adapter = new TaskAdapter(context,userName);
  459.         taskList.setAdapter(adapter);
  460.     }
  461.  
  462.  
  463.     public void addTask(View view)
  464.     {
  465.         //create builder
  466.         AlertDialog.Builder builder = new AlertDialog.Builder(context);
  467.         //set title
  468.         builder.setTitle("Add task");
  469.  
  470.         //set up the input
  471.         final EditText newTask = new EditText(context);
  472.         newTask.setHint("Enter new task....");
  473.         newTask.setInputType(InputType.TYPE_CLASS_TEXT);
  474.         builder.setView(newTask);
  475.  
  476.         builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  477.             @Override
  478.             public void onClick(DialogInterface dialogInterface, int i) {
  479.                 dialogInterface.dismiss();
  480.             }
  481.         });
  482.  
  483.         builder.setPositiveButton("Add Task", new DialogInterface.OnClickListener() {
  484.             @Override
  485.             public void onClick(DialogInterface dialogInterface, int i) {
  486.                 String myTaskTest = newTask.getText().toString();
  487.                 Toast.makeText(context, "task name:"+myTaskTest, Toast.LENGTH_SHORT).show();
  488.             }
  489.         });
  490.  
  491.         builder.show();
  492.     }
  493.  
  494.     public void addCustomTask(View view)
  495.     {
  496.         //create builder
  497.         AlertDialog.Builder builder = new AlertDialog.Builder(context);
  498.         //set title
  499.         builder.setTitle("Add new task");
  500.  
  501.         //inflate view from layout ->custom layout,null,false as defualt values
  502.         View viewInflated= LayoutInflater.from(context).inflate(R.layout.dlg_new_task,null,false);
  503.  
  504.         final EditText txtCustomTask = (EditText)viewInflated.findViewById(R.id.txtTask);
  505.  
  506.         builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  507.             @Override
  508.             public void onClick(DialogInterface dialogInterface, int i) {
  509.                 dialogInterface.dismiss();
  510.             }
  511.         });
  512.  
  513.         builder.setPositiveButton("Add task", new DialogInterface.OnClickListener() {
  514.             @Override
  515.             public void onClick(DialogInterface dialogInterface, int i) {
  516.                 dialogInterface.dismiss();
  517.                 String myTask = txtCustomTask.getText().toString();
  518.                 //Toast.makeText(context, "task is:"+myText, Toast.LENGTH_SHORT).show();
  519.                 myUtl.task(userName,myTask,false);
  520.                 /////
  521.                 setListData();
  522.             }
  523.         });
  524.  
  525.         //display our inflated view in screen
  526.         builder.setView(viewInflated);
  527.         //show the dialog
  528.         builder.show();
  529.  
  530.     }
  531.  
  532.     public void addYesNo(View view)
  533.     {
  534.         AlertDialog.Builder builder = new AlertDialog.Builder(context);
  535.         builder.setTitle("YES OR NO");
  536.         builder.setMessage("Wanta a fanta???");
  537.         builder.setPositiveButton("YES I WANT", new DialogInterface.OnClickListener() {
  538.             @Override
  539.             public void onClick(DialogInterface dialogInterface, int i) {
  540.                 Toast.makeText(context, "ENJOY", Toast.LENGTH_LONG).show();
  541.                 dialogInterface.dismiss();
  542.             }
  543.         });
  544.         builder.setNegativeButton("ON DIET", new DialogInterface.OnClickListener() {
  545.             @Override
  546.             public void onClick(DialogInterface dialogInterface, int i) {
  547.                 Toast.makeText(context, "GoodBye Fatty!!", Toast.LENGTH_SHORT).show();
  548.                 dialogInterface.dismiss();
  549.             }
  550.         });
  551.         builder.show();
  552.     }
  553. }
  554.  
  555.  
  556. activity_main.xml
  557. =====================
  558. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  559.     android:layout_width="match_parent"
  560.     android:layout_height="match_parent"
  561.     android:orientation="vertical">
  562.  
  563.     <LinearLayout
  564.         android:layout_width="match_parent"
  565.         android:layout_height="150dp"
  566.         android:orientation="vertical">
  567.  
  568.         <TextView
  569.             android:layout_width="match_parent"
  570.             android:layout_height="match_parent"
  571.             android:gravity="center"
  572.             android:text="LOGO"
  573.             android:textSize="100sp">
  574.  
  575.         </TextView>
  576.     </LinearLayout>
  577.  
  578.     <LinearLayout
  579.         android:layout_width="match_parent"
  580.         android:layout_height="100dp"
  581.         android:orientation="vertical">
  582.  
  583.         <EditText
  584.             android:id="@+id/txtUserName"
  585.             android:layout_width="match_parent"
  586.             android:layout_height="wrap_content"
  587.             android:hint="Enter your name...."
  588.             android:inputType="text"
  589.             android:textSize="22sp" />
  590.  
  591.         <EditText
  592.             android:id="@+id/txtUserPassword"
  593.             android:layout_width="match_parent"
  594.             android:layout_height="wrap_content"
  595.             android:hint="Enter Password..."
  596.             android:inputType="textPassword"
  597.             android:textSize="22sp" />
  598.     </LinearLayout>
  599.  
  600.     <LinearLayout
  601.         android:layout_width="match_parent"
  602.         android:layout_height="150dp"
  603.         android:orientation="vertical">
  604.  
  605.         <Button
  606.             android:layout_width="match_parent"
  607.             android:layout_height="wrap_content"
  608.             android:text="Login"
  609.             android:background="#00BFFF"
  610.             android:textColor="#ffffff"
  611.             android:textSize="32sp"
  612.             android:id="@+id/btnLogin"
  613.             android:layout_marginBottom="20dp"/>
  614.  
  615.         <Button
  616.             android:layout_width="match_parent"
  617.             android:layout_height="wrap_content"
  618.             android:text="Register"
  619.             android:background="#00BFFF"
  620.             android:textColor="#ffffff"
  621.             android:textSize="32sp"
  622.             android:id="@+id/btnRegister"/>
  623.     </LinearLayout>
  624.  
  625.     <LinearLayout
  626.         android:layout_width="match_parent"
  627.         android:layout_height="match_parent"
  628.         android:orientation="vertical">
  629.         <TextView
  630.             android:layout_width="match_parent"
  631.             android:layout_height="match_parent"
  632.             android:textSize="32sp"
  633.             android:text="MY LOGIN SYSTEM V1"
  634.             android:gravity="center"
  635.             android:id="@+id/lblMsg"/>
  636.     </LinearLayout>
  637. </LinearLayout>
  638.  
  639.  
  640.  
  641. activity_register.xml
  642. =====================
  643. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  644.     android:layout_width="match_parent"
  645.     android:layout_height="match_parent"
  646.     android:orientation="vertical">
  647.  
  648.     <TextView
  649.         android:layout_width="match_parent"
  650.         android:layout_height="wrap_content"
  651.         android:layout_marginTop="20dp"
  652.         android:gravity="center"
  653.         android:text="USER REGISTERTION"
  654.         android:textSize="32sp" />
  655.  
  656.     <RelativeLayout
  657.         android:layout_width="match_parent"
  658.         android:layout_height="match_parent">
  659.  
  660.         <EditText
  661.             android:layout_width="match_parent"
  662.             android:layout_height="wrap_content"
  663.             android:hint="Enter User Name...."
  664.             android:id="@+id/txtUserName"/>
  665.         <EditText
  666.             android:layout_width="match_parent"
  667.             android:layout_height="wrap_content"
  668.             android:hint="Enter password...."
  669.             android:id="@+id/txtPassword"
  670.             android:layout_below="@id/txtUserName"/>
  671.  
  672.         <EditText
  673.             android:layout_width="match_parent"
  674.             android:layout_height="wrap_content"
  675.             android:hint="Enter password again..."
  676.             android:id="@+id/txtPassword2"
  677.             android:layout_below="@id/txtPassword"/>
  678.         <Button
  679.             android:layout_width="150dp"
  680.             android:layout_height="wrap_content"
  681.             android:id="@+id/btnRegisterUser"
  682.             android:layout_below="@id/txtPassword2"
  683.             android:text="Register"/>
  684.         <Button
  685.             android:layout_width="150dp"
  686.             android:layout_height="wrap_content"
  687.             android:text="Cancel"
  688.             android:id="@+id/btnCancel"
  689.            android:layout_toEndOf="@id/btnRegisterUser"
  690.             android:layout_below="@id/txtPassword2"/>
  691.     </RelativeLayout>
  692.  
  693. </LinearLayout>
  694.  
  695.  
  696.  
  697. activity_welcome.xml
  698. =====================
  699. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  700.     android:layout_width="match_parent"
  701.     android:layout_height="match_parent"
  702.     android:orientation="vertical">
  703.  
  704.     <Button android:layout_width="match_parent"
  705.         android:layout_height="wrap_content"
  706.         android:text="ADD TASK"
  707.         android:onClick="addCustomTask"
  708.         />
  709.  
  710.     <ListView
  711.         android:layout_width="match_parent"
  712.         android:layout_height="match_parent"
  713.         android:id="@+id/taskList"/>
  714. </LinearLayout>
  715.  
  716.  
  717.  
  718. dlg_new_task.xml
  719. ======================
  720. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  721. android:layout_width="match_parent"
  722. android:layout_height="wrap_content"
  723. android:orientation="vertical"
  724.     android:gravity="center">
  725.  
  726. <ImageView
  727.     android:layout_width="100dp"
  728.     android:layout_height="100dp"
  729.     android:src="@drawable/task"/>
  730. <EditText
  731.     android:layout_width="200dp"
  732.     android:layout_height="wrap_content"
  733.     android:hint="Enter task"
  734.     android:id="@+id/txtTask"/>
  735. </LinearLayout>
  736.  
  737.  
  738.  
  739. task_item.xml
  740. =========================
  741. <?xml version="1.0" encoding="utf-8"?>
  742. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  743.     android:layout_width="match_parent"
  744.     android:layout_height="50dp"
  745.     android:orientation="horizontal"
  746.     android:layoutDirection="rtl"
  747.     android:layout_margin="20dp"
  748.     >
  749.  
  750.     <Switch
  751.         android:layout_width="40dp"
  752.         android:layout_height="wrap_content"
  753.         android:id="@+id/taskDone"
  754.         />
  755.     <TextView
  756.         android:layout_width="match_parent"
  757.         android:layout_height="wrap_content"
  758.         android:textSize="22sp"
  759.         android:id="@+id/taskName"
  760.         android:text="EXAMPLE FOR TASK"
  761.         />
  762. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement