Вы можете использовать среднюю программу owin для определения политики cors, в которой вы можете определить несколько корсовых происхождений
return new CorsOptions
{
PolicyProvider = new CorsPolicyProvider
{
PolicyResolver = context =>
{
var policy = new CorsPolicy()
{
AllowAnyOrigin = false,
AllowAnyMethod = true,
AllowAnyHeader = true,
SupportsCredentials = true
};
policy.Origins.Add("http://foo.com");
policy.Origins.Add("http://bar.com");
return Task.FromResult(policy);
}
}
};
После активности нет скобок. Это должно быть:
public class Main extends Activity {
Вы используете ;
после окончания ваших onCreate
и onOptionsItemSelected
. Вы не используете ;
в конце ваших методов.
В вашем коде много основных синтаксических ошибок. Я бы порекомендовал вам сначала изучить Java. Ниже приведен исправленный вариант вашего кода.
package com.example.mod7;
import java.text.DecimalFormat;
import com.example.mod7.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class Main extends Activity {
double costPerTicket=59.99;
int numberofTickets;
double totalCost;
String groupChoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText tickets= (EditText)findViewById(R.id.txtTickets);
final Spinner group = (Spinner)findViewById(R.id.txtGroups);
Button cost=(Button)findViewById(R.id.btnCost);
final TextView result=(TextView)findViewById(R.id.txtResult);
cost.setOnClickListener(new OnClickListener() {
@Override
public void onClick(view arg0) {
numberofTickets=Integer.parseInt(tickets.getText().toString());
totalCost=costPerTicket*numberofTickets;
DecimalFormat currency=new DecimalFormat("$###,###.##");
groupChoice=group.getSelectedItem().toString();
result.setText("Total cost for"+ groupChoice + "is"+ currency.format(totalCost));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}