如何实现这在Android中 [英] How Do Implement This In Android
问题描述
我是新的Android.Can谁能告诉我它是什么类型的技术?我想添加这个功能在密码字段。我想知道什么是达到我的目标,正确的方法是什么?你能帮助我与任何code或如何实现此链接到一个导向是否正确?
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?
推荐答案
您有许多可能性,创造这样的布局:
You have many possibilities to create this kind of layout:
- 父
RelativeLayout的
,一个的LinearLayout
4个点的顶部和底部显示你的看法< A HREF =http://developer.android.com/guide/topics/ui/layout/relative.html#Position相对=nofollow>属性的为toLeftOf,toRightOf等 - 使一个onClickListener
的方法来改变自己的状态,并保存该号码。 - 在多个
的LinearLayout
s的重量
属性充满整个空间,每一个的意见(四舍五入号)填写空间的(见下面的例子来了解权重属性)的 - 或多个RelativeLayout的
的S - 甚至TableLayout
。 - 或
的LinearLayout
和的GridView
下面有ItemClickListener
方法..
- 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..
据低于你的问题的意见,有很多的可能性。我选择其中具有线性和RelativeLayout的之一。这可能是这样的:
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>
而在你的活动
类,它实现 OnClickListener
是这样的:
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.
}
}
然后在你的 methodToSaveNumber
方法:
// 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
}
和只是向你展示它是如何工作的,可绘制 green_dots
可能是这样的:
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>
您必须告知你有关布局以及如何它的工作原理,在单击事件及其监听中, 可绘制及其状态(集中,pressed,残疾人,......),最后,我希望你能得到你想要的。
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.
编程快乐!
这篇关于如何实现这在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!