我在gridView
中有图片,我尝试打开下一张图片等......这很好用。但是大问题是来自另一个班级的呼叫按钮点击。
在头等舱:
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
final int position, long id) {
View layout = inflater.inflate(R.layout.custom_fullimage_dialog,
(ViewGroup) findViewById(R.id.layout_root));
final MyImageView image = (MyImageView)
layout.findViewById(R.id.fullimage);
btnPrevius = (Button) layout.findViewById(R.id.btnPrevius);
btnPrevius.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
etc...
现在我的问题,我需要从另一个班级做到这一点。
我的第一个想法是,当第一类中需要其他类调用方法时,会调用按钮点击。
但我不能这样做,因为我总是得到零点异常。
我尝试写第一堂课:
public void Move(Integer next){
setContentView(R.layout.report_imagegrid);
Button btnPrevius = (Button) findViewById(R.id.btnPrevius);
btnPrevius.callOnClick();
}
}
我尝试在多路上找到按钮,但我总是得到null:/
在头等舱的最后我有网格视图,按钮更改图像。 第二类需要从中访问此按钮并触发按钮,以更改图像。
有可能吗?
感谢名单
答案 0 :(得分:0)
你的问题不是那么清楚。但试着用这个。 使按钮上一个静态像..
public class MianActivity extends Activity{
public static Button btnPrevious
//do this before on create and then in on create initialize it as usual
然后尝试在另一个类中使用它:
MainActivity.btnPrevious.callonClick //whatever your function name is