我有一个微调器(动态),其中包含一个ID列表,每个ID都有一个产品值。当我点击特定ID时,需要更改与该ID相关联的值。
我有一个包含表格的listView。该表包含产品名称,产品价格和产品信息。当我更改ID时,表信息(listview)会更改但不会更改产品值(这是textview而不是listview的一部分)。
我使用来自不同类的意图传递产品值。我如何做到这一点,当我在微调器中更改项目时,产品值会更改?
/**
* Listener for flight leg selection of spinner
*/
private OnItemSelectedListener onFlightLegSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
new ShowSalesReportAsyncTask(flightLegMap.get(flightLegs.get(position)), position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing
}
};
这是我获得产品价值的onCreate。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sales_report);
salesReportListView = (ListView) findViewById(R.id.sales_report_listview);
spinnerFlightLegs = (Spinner) findViewById(R.id.flight_legs);
noTransactionsWarning = (TextView) findViewById(R.id.no_transactions_warning);
totalValueNetAmount = (TextView) findViewById(R.id.total_currency_net_value);
String salesRevenue = TOTAL_VALUE;
Bundle extras = getIntent().getExtras();
if (extras != null) {
salesRevenue = extras.getString(TOTAL_VALUE);
}
totalValueNetAmount.setText(salesRevenue);
flightLegMap = getAllFlightLegs();
if (!flightLegMap.isEmpty()) {
setFlightLegSpinner();
btnShare.setEnabled(true);
} else {
btnShare.setEnabled(false);
}
spinnerFlightLegs.setOnItemSelectedListener(onFlightLegSelectedListener);
salesReportListAdapter = new SalesReportListAdapter(this);
salesReportListView.setAdapter(salesReportListAdapter);
这是我用来用数据填充视图的异步任务。
私有类ShowSalesReportAsyncTask扩展了AsyncTask&gt; {
private String flightLeg;
private int position;
public ShowSalesReportAsyncTask(String flightLeg, int position) {
this.flightLeg = flightLeg;
this.position = position;
}
@Override
protected List<Purchase> doInBackground(Void... params) {
List<Purchase> rows = new ArrayList<Purchase>();
PurchaseDao purchaseDao = new PurchaseDao(flightLeg, MIUtils.getShardDatabaseIndexMap());
LOG.debug(TAG + "Getting report for : {}", flightLeg);
// double netTotal = SalesUtil.calculateFlightTransactionTotal(purchaseDao, refundDao,());
return purchaseDao.getSuccessfulTransactions();
}
@Override
protected void onPostExecute(List<Purchase> result) {
super.onPostExecute(result);
if (!result.isEmpty()) {
noTransactionsWarning.setVisibility(View.GONE);
} else {
noTransactionsWarning.setVisibility(View.VISIBLE);
}
salesReportListAdapter.setRowsAndFlightDetails(result, flightLegMap.get(flightLegs.get(position)),
spinnerFlightLegs.getSelectedItem().toString());
totalValueNetAmount.setText((int) netTotal);
}
}
需要更改的项目是“EUR”。 SPINNER TABLE IMAGE
答案 0 :(得分:0)
添加代码以在活动的onStart()方法中注册侦听器。这应该有用。
这应该更好地回答您的问题 - How to keep onItemSelected from firing off on a newly instantiated Spinner?