Разница между Spinner OnItemSelectedListener и AutoCompleteTextView OnItemClickListener - PullRequest
0 голосов
/ 10 января 2012

У меня Spinner вид внутри TableRow

и следующий OnItemSelectedListener код

public class OnProductItemSelectedListener implements OnItemSelectedListener {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        ViewGroup parentRowView = (ViewGroup) parent.getParent();
        Log.i(MY_DEBUG_TAG,"Class: "+parentRowView.getClass().getName());
        // I got it as TableRow
        TableLayout salesTable = (TableLayout) findViewById(R.id.salesTable);
        for(int i = 1; i < salesTable.getChildCount();  i++) {
            TableRow row = (TableRow) orderLines.getChildAt(i);
            if(row.getTag() == parentRowView.getTag() ) {
                ....

Я теперь изменил Spinner на AutoCompleteTextView.

теперь у меня есть AutoCompleteTextView вид внутри TableRow

и следующие OnItemClickListener

private OnItemClickListener productOnItemClickListener = new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ViewGroup parentRowView = (ViewGroup) parent.getParent();
        Log.i(MY_DEBUG_TAG,"Class: "+parentRowView.getClass().getName());
        // I got it as  Class:android.widget.PopupWindow$PopupViewContainer
        // I need get the TableRow holding the AutoCompleteTextView here

Как я могу получить TableRow, содержащий AutoCompleteTextView?

- Обновление

Вот как я заполняю TableRows программно и устанавливаю теги

TableLayout salesTable = (TableLayout) findViewById(R.id.salesTable);
TableRow row = new TableRow(this);

AutoCompleteTextView productAutoComplete = new AutoCompleteTextView(this);
params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
productAutoComplete.setLayoutParams(params);
productAutoComplete.setId(R.id.autocomplete_product);
row.addView(productAutoComplete);
ProductAdapter productAdapter = new ProductAdapter(this, R.layout.product_auto, productList);
productAutoComplete.setAdapter(productAdapter);
productAutoComplete.setOnItemClickListener(productOnItemClickListener);
productAutoComplete.setOnKeyListener(productOnKeyListener);

/*
Spinner pSpinner = new Spinner(this);
params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
pSpinner.setLayoutParams(params);
pSpinner.setId(R.id.product_spinner);
row.addView(pSpinner);
ArrayAdapter<Product> spinnerArrayAdapter = new ArrayAdapter<Product>(this, android.R.layout.simple_spinner_item, productList);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
pSpinner.setAdapter(spinnerArrayAdapter);
pSpinner.setPrompt("Select a Product");
Log.i(MY_DEBUG_TAG, "Setting spinner on click.");
pSpinner.setOnItemSelectedListener(new OnProductItemSelectedListener());
*/

Date now = new Date();
row.setTag(now.toGMTString());
salesTable.addView(row, new TableLayout.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
... ad more rows to the table here
...