3

前のlineaLayoutのedittextがフォーカスを失うたびに、3つのeditTextを含むlinearLayoutを膨らませるこのコードがあります。最近作成された editTexts のみに onFocusChangeListener を設定したいと考えています。代わりに、最初の linearLayout がフォーカスを失ったときにのみ onFocusChangeListener が呼び出され、残りの残りのレイアウトは呼び出されません。

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をリッスンしました)。ヘルプ!!!

4

1 に答える 1

0

新しく作成されたタイプのインスタンスを使用して、この内部クラスのインスタンスでリスナーをセットアップできるように、View.OnFocusChangeListenerとメソッドを実装する内部クラスが必要な場合があるEditText独自のタイプを作成するために、クラスを拡張する必要があります。Viewpublic

于 2013-08-15T18:26:53.547 に答える