Im新的android編程,我正嘗試構建一個應用程序與圖像打開一個新的活動爲每個圖像視圖點擊與他們自己的圖像視圖。到目前爲止,我已經完成了我的主要活動,並將其上的4個圖像視圖全部放在彼此之下並受到約束。在我打開應用程序的意義上,所有工作都很好,圖像視圖展示了它們應該如何,我可以點擊imageview1,然後是2,然後是3,然後是4,然後是其中任何一個。但如果我打開應用程序,並嘗試點擊imageview 2第一或imageview 3例如,或imageview 4然後它不起作用。我必須從1開始,然後繼續2,然後3和4,最後我可以自由導航。我怎樣才能解決這個問題?我之前已經發布了我的主要活動java文件。任何幫助,將不勝感激。問題與圖像視圖和onClickListener
package com.ntq.ntqapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
public class MainActivity1 extends AppCompatActivity {
private ImageView ts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
ts = (ImageView)findViewById(R.id.ts1);
ts.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Intent myIntent = new Intent(MainActivity1.this, imageView1.class);
startActivity(myIntent);
ts = (ImageView)findViewById(R.id.ts2);
ts.setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
Intent myIntent = new Intent(MainActivity1.this, imageView2.class);
startActivity(myIntent);
ts = (ImageView)findViewById(R.id.ts3);
ts.setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
Intent myIntent = new Intent(MainActivity1.this, imageView3.class);
startActivity(myIntent);
ts = (ImageView) findViewById(R.id.ts4);
ts.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), imageView4.class);
startActivity(myIntent);
}
}
);
}}
);
}});}});}}
兄弟...我愛你。這是那些肯定與括號現在它應該如何工作。非常感謝 :) – Essentialz