谁能告诉我为什么这不起作用?我根本没有错误,但根本不起作用。
在我添加 ScreenSwipe 之前,这实际上可以正常工作,现在我无法弄清楚出了什么问题。
谢谢
package com.sample.sample
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
public class PageOneFragment extends Fragment {
ImageButton btn1;
static int i = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.page1_layout, container, false);
btn1 = (ImageButton) rootView.findViewById(R.id.m1_btn);
return rootView;
}
public void setupPlayPauseButton1(View view) {
btn1 = (ImageButton) view.findViewById(R.id.m1_btn);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i +=1;
if (i % 2 == 0) {
btn1.setImageResource(R.drawable.pause);
} else {
btn1.setImageResource(R.drawable.play);
}
}
});
}
}
编辑
这是正确的吗?
package com.wepromoteme.brapp;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
public class PageOneFragment extends Fragment {
ImageButton btn1;
int i = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.page1_layout, container, false);
btn1 = (ImageButton) rootView.findViewById(R.id.m1_btn);
setupPlayPauseButton1(rootView);
return rootView;
}
private void setupPlayPauseButton1(View view) {
btn1 = (ImageButton) view.findViewById(R.id.m1_btn);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i +=1;
if (i % 2 == 0) {
btn1.setImageResource(R.drawable.pause);
} else {
btn1.setImageResource(R.drawable.play);
}
}
});
}
}