我在使用Android studio 3.0.1。我在android cardview上工作了一个项目。我在android cardview上看到了一个视频教程。我仔细编写代码。但是当我运行代码时,它看到了一些错误。
以下是我MainActivity.java
private void setSingleEvent(GridLayout mainGrid) {
//Loop all child item of Main Grid
for (int i = 0; i < mainGrid.getChildCount(); i++) {
//You can see , all child item is CardView , so we just cast object to CardView
CardView cardView = (CardView) mainGrid.getChildAt(i);
final int finalI = i;
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (finalI == 0) //Teachers Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Teachers.class);
startActivity(intent);
}
else if (finalI == 1) //Students Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Students.class);
startActivity(intent);
}
else if (finalI == 2) //Students Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Students.class);
startActivity(intent);
}
else if (finalI == 3) //Notices Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Notices.class);
startActivity(intent);
}
else if (finalI == 4) //Results Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Results.class);
startActivity(intent);
}
else if (finalI == 5) //Phones Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Phones.class);
startActivity(intent);
}
else if (finalI == 6) //Blood Activities
{
Intent intent = new Intent( packageContext: MainActivity.this, Bloods.class);
startActivity(intent);
}
else {
Toast.makeText(MainActivity.this, "Activvvv", Toast.LENGTH_SHORT).show();
}
}
});
}
}
答案 0 :(得分:0)
删除红色的ints = []
for x in amount:
if 'million' in x:
ints.append(int(float(x.split()[0]) * 10**6))
elif ',' in x:
ints.append(int(x.replace(',','')))
else:
ints.append(0)
。最终的功能应如下所示。
[60000000, 1000000, 0, 1150000, 1000000, 0, 2480000, 0, 0, 75000000, 1250000, 3000000, 67000, 4000000, 0, 63000000, 5900000, 170000, 5000000, 22000000, 15750000, 36500000, 0, 0, 0, 19900000, 0]
答案 1 :(得分:0)
Android Studio抱怨因为以下语句在Java中语法错误:
Intent intent = new Intent( packageContext: MainActivity.this, Notices.class);
Android Studio在方法参数之前显示参数名称(如“packageContext:”),以便为Android提供一些Kotlin外观和感觉。这对于初学者来说可能会让人感到困惑。声明的正确形式是:
Intent intent = new Intent(MainActivity.this, Notices.class);