I have a problem with my “findViewById” and it is occuring between the line.
new AlertDialog.Builder(DetailShareHoldingActivity.this).setTitle("Köp " + Portfolio.getPortfolio().getShareHolding(positionList).getName() + " Aktier").setView(addView).setPositiveButton("Köp", new DialogInterface.OnClickListener() {
and the line
public void onClick(DialogInterface dialog, int whichButton) {
If I place the line any other where it works fine, problem is that I must have the line exactly where I have it, so I don’t know why its complaining?
Here is my OnclickListener
buyButton = (Button)findViewById(R.id.buyButton);
buyButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
EditText tempEditText;
final View addView = getLayoutInflater().inflate(R.layout.shop_exsisting_share, null);
new AlertDialog.Builder(DetailShareHoldingActivity.this).setTitle("Köp " + Portfolio.getPortfolio().getShareHolding(positionList).getName() + " Aktier").setView(addView).setPositiveButton("Köp", new DialogInterface.OnClickListener() {
tempEditText = (EditText)findViewById(R.id.nrOfSharesInPortfolioEdit);//Complains on findViewById "Return type for the method is missing" and I have to have the code exactly here so that it is visible when the dialog is created and not when the button is pressed.
tempEditText= (EditText) findViewById(R.id.nrOfSharesInPortfolioEdit);
tempEditText.setText(Portfolio.getPortfolio().getShareHolding(positionList).getNrOfSharesInPortfolio());
System.out.println(Portfolio.getPortfolio().getShareHolding(positionList).getNrOfSharesInPortfolio());
tempEditText= (EditText) findViewById(R.id.currentCourseEdit);
tempEditText.setText(Double.toString(Portfolio.getPortfolio().getShareHolding(positionList).getCurrentRate()));
public void onClick(DialogInterface dialog, int whichButton) {
System.out.println("Button pressed köp ");
}
}).setNegativeButton("Avbryt", null).show();
}
});
Yes, of course you’re having problems. You’re trying to define already-declared variables within a class definition… which isn’t allowed.
Your comment says, “I have to have the code exactly here so that it is visible when the dialog is created and not when the button is pressed.“. This doesn’t make any sense; you need to have your code in an actual method.
Move your definitions outside of the class definition and into a method instead.