不断出现错误 "Conflicting declarations: val open: ImageButton, val open: ImageButton"
Keep getting error "Conflicting declarations: val open: ImageButton, val open: ImageButton"
我仍在创建我的应用程序。我正试图让它到达我单击 imabe 按钮时它将转到新 activity 的位置。每个图像按钮都在 activity.
上
代码*
`
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card2)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card3)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card4)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card5)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Hdt::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card6)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GCP::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card7)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, SP::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card8)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Cummins::class.java)
startActivity(intent)
})
}
}`
当它像这样设置时它可以工作,但只有当我点击第一个然后转到第二个时,依此类推列表。
代码*
`
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card2)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card3)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card4)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card5)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,Hdt::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card6)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,GCP::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card7)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,SP::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card8)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,Cummins::class.java)
startActivity(intent)
})
})
})
})
})
})
})
})
}
}`
变化:
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
收件人:
val card1: ImageButton = findViewById<ImageButton>(R.id.card1)
card1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
对其他按钮也这样做
喜欢
val open1: ImageButton = findViewById<ImageButton>(R.id.card1)
val open2: ImageButton = findViewById<ImageButton>(R.id.card2)
val open3: ImageButton = findViewById<ImageButton>(R.id.card3)
val open4: ImageButton = findViewById<ImageButton>(R.id.card4)
val open5: ImageButton =findViewById<ImageButton>(R.id.card5)
val open6: ImageButton =findViewById<ImageButton>(R.id.card6)
val open7: ImageButton =findViewById<ImageButton>(R.id.card7)
val open8: ImageButton =findViewById<ImageButton>(R.id.card8)
open1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
open1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
})
open2.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
})
open3.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
})
open4.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Hdt::class.java)
startActivity(intent)
})
open5.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GCP::class.java)
startActivity(intent)
})
open6.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, SP::class.java)
startActivity(intent)
})
open7.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Cummins::class.java)
startActivity(intent)
})
我仍在创建我的应用程序。我正试图让它到达我单击 imabe 按钮时它将转到新 activity 的位置。每个图像按钮都在 activity.
上代码*
`
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card2)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card3)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
})
val open: ImageButton = findViewById<ImageButton>(R.id.card4)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card5)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Hdt::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card6)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GCP::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card7)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, SP::class.java)
startActivity(intent)
})
val open: ImageButton =findViewById<ImageButton>(R.id.card8)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Cummins::class.java)
startActivity(intent)
})
}
}`
当它像这样设置时它可以工作,但只有当我点击第一个然后转到第二个时,依此类推列表。
代码*
`
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card2)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card3)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
val open: ImageButton = findViewById<ImageButton>(R.id.card4)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card5)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,Hdt::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card6)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,GCP::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card7)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,SP::class.java)
startActivity(intent)
val open: ImageButton =findViewById<ImageButton>(R.id.card8)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity,Cummins::class.java)
startActivity(intent)
})
})
})
})
})
})
})
})
}
}`
变化:
val open: ImageButton = findViewById<ImageButton>(R.id.card1)
open.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
收件人:
val card1: ImageButton = findViewById<ImageButton>(R.id.card1)
card1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
对其他按钮也这样做
喜欢
val open1: ImageButton = findViewById<ImageButton>(R.id.card1)
val open2: ImageButton = findViewById<ImageButton>(R.id.card2)
val open3: ImageButton = findViewById<ImageButton>(R.id.card3)
val open4: ImageButton = findViewById<ImageButton>(R.id.card4)
val open5: ImageButton =findViewById<ImageButton>(R.id.card5)
val open6: ImageButton =findViewById<ImageButton>(R.id.card6)
val open7: ImageButton =findViewById<ImageButton>(R.id.card7)
val open8: ImageButton =findViewById<ImageButton>(R.id.card8)
open1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, TMs::class.java)
startActivity(intent)
})
open1.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Schematics::class.java)
startActivity(intent)
})
open2.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, PartsCheatSheets::class.java)
startActivity(intent)
})
open3.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GeneratorLoadWiring::class.java)
startActivity(intent)
})
open4.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Hdt::class.java)
startActivity(intent)
})
open5.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, GCP::class.java)
startActivity(intent)
})
open6.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, SP::class.java)
startActivity(intent)
})
open7.setOnClickListener(View.OnClickListener {
val intent = Intent(this@MainActivity, Cummins::class.java)
startActivity(intent)
})