How Do Implement This In Android [closed]
Asked Answered
H

1

-1

I am new in Android.Can anyone tell me What type of Technology it is ? I want to add this feature in password field. May I know what is the correct way to achieve my objective?Can you help me with any code or a link to a guide on how to implement this correctly?

Here answered 24/3, 2014 at 6:36 Comment(8)
Buttons with circle background and relativelayout. And for the top a circle empty view which is filled with the codeIleenileitis
Is there any link/Tutorials for this ? @MarcoAciernoHere
i think 10 buttons in rel. layout below a rel.layout with 4 rounded images.. then first passcode cliked then change image of 1st btn in 1st rel layout.. repeat it 4 timesPamphylia
for the top pins of images, create LinearLayout with orientation horizontal and add four ImageViews in it. and for the keys, create a GridView with items count equal to 12 and return ImageViews in getView(), return ImageViews with transparent images for positions of 9 and 11...Singleaction
@GopalRao Sir is there any demo/tutorial for this ?Here
@Amiya There will be no tutorial for your particular requirements... Just you need to be aware of layoutsSingleaction
@GopalRao Sir : Please take a look #22633845Here
Just to add, this is not in accordance with android design guideline.Sequestrate
F
2

You have many possibilities to create this kind of layout:

  • A parent RelativeLayout, a LinearLayout with 4 dots at the top and for the bottom display your views with the attributes as toLeftOf, toRightOf, etc. - make an onClickListener method to change their state and save the number.
  • Multiple LinearLayouts with weight attributes to fill the entire space and each of the views (rounded number) fill the space (see the example below to understand the weight attribute) - or several RelativeLayouts - or even a TableLayout.
  • Or LinearLayout and GridView below with an ItemClickListener method..

According to the comments below your question, there is a lot of possibilities. I choose one of them with Linear and RelativeLayout. It might be something like this:

<!-- named activity_main.xml -->
<RelativeLayout
    ... >
    <LinearLayout
        android:id="@+id/contain"
        ... android:layout_width="250dip"
        android:orientation="horizontal"
        android:weightSum="4" >
        <!-- weightSum to 4 = whatever the screen, display 
             my children views in 4 sections -->
        <View
            ... android:layout_weight="1"
            android:background="@drawable/green_dots" />
        <!-- weight to 1 = this takes one section -->
        <View
            ... android:layout_weight="1"
            android:background="@drawable/green_dots" />
        <!-- weight to 1 = this takes one section -->
        <View
            ... android:layout_weight="1"
            android:background="@drawable/green_dots" />
        <View
            ... android:layout_weight="1"
            android:background="@drawable/green_dots" />
    </LinearLayout>
    <RelativeLayout
        android:layout_below="@id/contain" ... >
        ... Here display your buttons (or textviews) with 
            custom drawable background for each one
</RelativeLayout>  

And in your Activity class, it implements OnClickListener like this:

public class MyActivity extends Activity implements OnClickListener { }

Then in your methods inside this Activity:

// init your buttons var
Button one, two, three, four, five ...;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set the layout above
    setContentView(R.layout.activity_main);
    // init your buttons
    one = (Button) findViewById(R.id.button1);
    two = (Button) findViewById(R.id.button2);
    three = (Button) findViewById(R.id.button3);
    ... etc.

    // set them to your implementation
    one.setOnClickListener(this);
    two.setOnClickListener(this);
    three.setOnClickListener(this);
    ... etc.
}

// call this function when one button is pressed
public void onClick(View view) {
    // retrieves the id of clicked button
    switch(view.getId()) {
        case R.id.button1:
             methodToSaveNumber(int);
        break;
        case R.id.button2:
             methodToSaveNumber(int);
        break;
        case R.id.button3:
             methodToSaveNumber(int);
        break;
        ... etc.
    }
}

Then in your methodToSaveNumber method:

// finally, your method to save the number of the password
public void methodToSaveNumber(int i) {
    ... do something. 
    ... change the state of the buttons, the dots, whatever you want
}  

And just to show you how it works, the drawable green_dots might be like this:

<?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <!-- radius -->
    <corners
        android:radius="20dp" />
    <!-- border -->
    <stroke 
        android:color="@android:color/green"
         android:width="2dp" />
    <!-- background (transparent) -->
    <solid 
         android:color="#00000000" />
</shape>  

You must to inform you about the layouts and how it works, the click event and its listener, the drawables and their states (focused, pressed, disabled, ...), and finally, I hope you will get what you want.

Happy coding!

Flub answered 24/3, 2014 at 8:2 Comment(3)
Thanks for Answer. I want to add your approach .Here
Glad to help. Not sure if it's the best one but this might be a good start and I think it's the easy one when you begin.Flub
I think you already have an answer @IntelliJAmiya :) Use the SharedPreferences, save the activities states and retrieve them when you reopen the app, on the first activity (A). It should work and it's not hard to do.Flub

© 2022 - 2024 — McMap. All rights reserved.