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?
How Do Implement This In Android [closed]
You have many possibilities to create this kind of layout:
- A parent
RelativeLayout
, aLinearLayout
with 4 dots at the top and for the bottom display your views with the attributes as toLeftOf, toRightOf, etc. - make anonClickListener
method to change their state and save the number. - Multiple
LinearLayout
s withweight
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 severalRelativeLayout
s - or even aTableLayout
. - Or
LinearLayout
andGridView
below with anItemClickListener
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!
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.
ImageView
s in it. and for the keys, create aGridView
with items count equal to 12 and returnImageView
s ingetView()
, returnImageView
s with transparent images for positions of 9 and 11... – Singleaction