你好我的朋友),我有我的課下一個錯誤......錯誤:無法指非final的變量名在不同的方法定義的內部類中
public class AlertDlg {
public static void AlertShow(final Activity activity, EditText name, EditText track)
{
LayoutInflater inflater = activity.getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.layout_custom_dialog, null);
name = (EditText) alertLayout.findViewById(R.id.et_name);
track = (EditText) alertLayout.findViewById(R.id.et_track);
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
alert.setTitle("Add track number");
//alert.setIcon(R.drawable.plus);
alert.setView(alertLayout);
alert.setCancelable(false);
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(activity.getBaseContext(), "Abort", Toast.LENGTH_SHORT).show();
}
});
alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ERROR HERE--->String sname = name.getText().toString();
//String track = etPassword.getText().toString();
Toast.makeText(activity.getBaseContext(), "Name: " + sname +" "+ " Track: " , Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = alert.create();
dialog.show();
}}
錯誤:無法指在不同的方法中定義的內部類內的非最終變量名。我試圖從該數據的EditText。但得到這個錯誤...
調用一個方法:
AlertDlg.AlertShow(MainActivity.this,name,track);
讓'name'爲''喜歡公共靜態無效AlertShow(最終活動活動,最終的EditText名,最終的EditText軌道)' –
有趣的final'是他alredy爲活動做了 – Blackbelt
然後我在這裏得到一個錯誤:
name = (EditText) alertLayout.findViewById(R.id.et_name);
錯誤:The final local variable name cannot be assigned. It must be blank and not using a compound assignment
– Yaroslav