Java android接口回调问题

Java android接口回调问题,java,android,Java,Android,目前我有两节课。主类和返回LinearLayout的LinearLayout类 layout类有一个button和一个edittext视图,它将把所有内容打包并返回一个视图给主类使用 在主类中将有一个ArrayList,它将在这里动态创建,然后在最后显示它们 问题 我想在每个按钮上使用QR扫描仪。我将上下文传递给LinearLayout类,以便在单击按钮时创建组件和扫描仪。它在点击布局列表中的每个已创建按钮时工作,并自动回调到主类onActivityResult方法 但是我想更新单击的linea

目前我有两节课。主类和返回LinearLayout的LinearLayout类

layout类有一个button和一个edittext视图,它将把所有内容打包并返回一个视图给主类使用

在主类中将有一个ArrayList,它将在这里动态创建,然后在最后显示它们

问题 我想在每个按钮上使用QR扫描仪。我将上下文传递给LinearLayout类,以便在单击按钮时创建组件和扫描仪。它在点击布局列表中的每个已创建按钮时工作,并自动回调到主类onActivityResult方法

但是我想更新单击的linearLayout的文本视图

我不知道如何获取回调后单击buttonlinearLayout的位置

我感觉这和回调/接口有关。但我不知道如何充分利用它

LinearLayout的代码为呼叫搜索栏:

EditText et;
Button bt;
LinearLayout ll;
IntentIntegrator _scanner;

public SearchBar(Context c){
    et=new EditText(c);
    bt=new Button(c);
    //et.setHint("WayPoint");
    bt.setText("Scan");
    _scanner = new IntentIntegrator((Activity) c);

    ll=new LinearLayout(c);
    setLinearLayout();

    bt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            _scanner.initiateScan();
        }
    });

    et.setLayoutParams(flowLeft());
    bt.setLayoutParams(flowRight());

    ll.addView(et);
    ll.addView(bt);
}
public LinearLayout getSearchBar(){
    return ll;
}
主要类别的简要代码:

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_search);

    //_scanner = new IntentIntegrator(this);

    //button_scan = (Button) findViewById(R.id.button_scan); 

    ScrollView sv = new ScrollView(this); 
    ll = new LinearLayout(this);        
    ll.setOrientation(LinearLayout.VERTICAL); 

    l2=new LinearLayout(this);      
    l2.setOrientation(LinearLayout.VERTICAL); 
    ll.addView(l2);

    //testing for searchBar class
    SearchBar origin= new SearchBar(this);
    origin.setHint("Origin");
    origin.setText("me");
    sbs.add(origin);
    ll.addView(sbs.get(0).getSearchBar());

    destin= new SearchBar(this);
    destin.setText("destin");
    destin.setHint("destination");
    destinLayout=destin.getSearchBar();
    sbs.add(destin);
    ll.addView(destinLayout);

    sv.addView(ll); 
    this.setContentView(sv);       
}


函数public void onClickView v具有View参数。你可以用它做任何你想做的事情,包括getId或getParent。也许您想调用v.getParent并将其存储在一个类变量中,以便您可以在onActivityResult?中访问它。

它的所有动态视图,因此它是按钮和编辑文本。getId总是返回-1,似乎不起作用,您只需要调用getParent并存储它。然后在onActivityResult中调用parent.getChildAtx,其中x是editText的索引
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == IntentIntegrator.REQUEST_CODE) { // from Barcode Scanner
        if (resultCode == RESULT_OK)
        {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
            if (scanResult == null){
                //Alert.ShowAlert(this, "Scanning", "Scan Failed");
            }else {
                String scanned = scanResult.getContents();

                //How to get position of which button was fired

            }
        }
    }
}