关于ImageButton的数组定义

Redknot 2013-08-09 08:48:24
这是我的代码,运行不下去,大家看看那肿么了?
package redknot.example.elements;
import android.app.Activity;
import android.content.Intent;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.ImageButton;

public class MainActivity extends Activity {

private ImageButton[] yuansu;

protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findView();

MyOnTouchListener touch = new MyOnTouchListener();
MyButton listener = new MyButton();

for(int j = 0;j <= 6;j++){
yuansu[j].setOnClickListener(listener);
}

}




class MyButton implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,Information.class);
startActivity(intent);
}

}


public void findView(){
yuansu[0] = (ImageButton) findViewById(R.id.h1);
yuansu[1] = (ImageButton) findViewById(R.id.li1);
yuansu[2] = (ImageButton) findViewById(R.id.na1);
yuansu[3] = (ImageButton) findViewById(R.id.k1);
yuansu[4] = (ImageButton) findViewById(R.id.rb1);
yuansu[5] = (ImageButton) findViewById(R.id.cs1);
yuansu[6] = (ImageButton) findViewById(R.id.fr1);

}
...全文
76 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Redknot 2013-08-09
  • 打赏
  • 举报
回复
已经解决了,还是我Java基础不好,数组定义的时候写成 private ImageButton[] yuansu = new ImageButton[7]; 就好了

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧