如何实现这在Android中 [英] How Do Implement This In Android

查看:111
本文介绍了如何实现这在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid.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 =htt​​p://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, 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..

据低于你的问题的意见,有很多的可能性。我选择其中具有线性和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆