如何设置onFocusChangeListener()上动态创建的一套editTexts的? [英] How to setup onFocusChangeListener() on a dynamically created set of editTexts?

查看:203
本文介绍了如何设置onFocusChangeListener()上动态创建的一套editTexts的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code中,我夸大含3 editTexts每次的previous lineaLayout失去焦点的一个EditText一个LinearLayout中。我想对最近只创建editTexts的onFocusChangeListener。相反,onFocusChangeListener被称为只有当第一的LinearLayout失去焦点,而不是其他人的休息。

i have this code in which i inflate a linearLayout containing 3 editTexts everytime an edittext of the previous lineaLayout loses focus. I want to have the onFocusChangeListener on the most recent created editTexts only. Instead, onFocusChangeListener is called only when the the first linearLayout loses focus and not the rest of others.

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sale_purchase_vouch);
    no=0;
    for(int i=0;i<30;i++)
        flag[i]=true;

    save=(Button)findViewById(R.id.Save);
    save.setText("Confirm Purchase");
    LayoutInflater l=getLayoutInflater();
    container=(LinearLayout)findViewById(R.id.container);
    row[no]=(LinearLayout)l.inflate(R.layout.row, container);
    items[no]=(AutoCompleteTextView)row[no].findViewById(R.id.item);
    quants[no]=(EditText)row[no].findViewById(R.id.quant);
    rates[no]=(EditText)row[no].findViewById(R.id.rate);

    quants[no].setOnFocusChangeListener(this);
    flag[no]=false;


}


@Override
public void onFocusChange(View arg0, boolean arg1) {
    // TODO Auto-generated method stub
    if(flag[no+1]==true){

        if(arg1==false){
            no++;
    LayoutInflater g=getLayoutInflater();

    row[no]=(LinearLayout)g.inflate(R.layout.row, container);
    items[no]=(AutoCompleteTextView)row[no].findViewById(R.id.item);
    quants[no]=(EditText)row[no].findViewById(R.id.quant);
    rates[no]=(EditText)row[no].findViewById(R.id.rate);
    Log.d("detection", "Row is "+ no+ arg0.getId());
        }
    }
}

我创建布尔数组知道最后EDITTEXT是否已经创建了一个新的LinearLayout(听了onFocusChangeListener)。帮助!

I created an array of boolean to know whether the last editText had created a new linearLayout(listened to the onFocusChangeListener). help!!!

推荐答案

您需要延长的EditText 类,所以你创建你自己的类型的查看其中,可能想将实施的 View.OnFocusChangeListener 公共方法,这样你就可以设置监听器使用新创建类型的实例这个内部类的一个实例。

You need to extend the EditText class so you create your own type of View where might want to have an inner class which will implement View.OnFocusChangeListener and public method so you can setup listener with an instance of this inner class using the instance of newly created type.

这篇关于如何设置onFocusChangeListener()上动态创建的一套editTexts的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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