我在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