드로어 블에 2 장의 그림이 있습니다. 내가하고 싶은 일은 작은 "다음"버튼이있는 첫 번째 이미지를 보여주고 다음 버튼을 클릭하면 다른 이미지는 "이전"버튼과 함께 표시되어야합니다. 그리고 이전 버튼을 클릭하면 첫 번째 이미지가 "다음"버튼과 함께 표시되어야합니다. 여기 내 코드입니다 :다음과 이전 버튼을 사용하여 두 이미지를 전환하는 방법은 무엇입니까?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class Piqlout extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.piq);
Button next= (Button) findViewById(R.id.next);
if (next.getText().equals("Next")) {
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView img = (ImageView) findViewById(R.id.imageview);
img.setImageResource(R.drawable.piq2);
Button next= (Button) findViewById(R.id.next);
next.setText("Prev");
}
});
}
if (next.getText().equals("Prev")){
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView img = (ImageView) findViewById(R.id.imageview);
img.setImageResource(R.drawable.piq1);
Button next= (Button) findViewById(R.id.next);
next.setText("Next");
}
});
}
}
}
여기 내 레이아웃입니다 : 무슨 일이 일어나고 무엇
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/piq1" />
<Button
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="10dp"
android:layout_gravity="bottom|right"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@drawable/buttonback"
android:textColor="#000000"
android:text="Next" />
</FrameLayout>
는 첫 번째 이미지는 "다음"버튼이 표시된다. 다음을 클릭하면 두 번째 이미지도 나오고 버튼 텍스트는 "이전"으로 바뀝니다. 그러나 prev를 클릭하면 아무 일도 일어나지 않습니다 (첫 번째 이미지는 표시되지 않습니다). 도와주세요.
Prev를 검사 할 때 if 문을 제거하고 첫 번째 if 문에 else 문을 연결하십시오. 그런; if (next) {} else {} – Aashir
아니요. 아직도 똑같은 일이 일어나고있다 –