我试图通过单击“下一步”按钮来显示图像,但此代码不起作用。
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
public class MyGridView extends Activity {
GridView mGridView;
int counter,i;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mygridacti);
mGridView = (GridView)findViewById(R.id.grdvw);
//mGridView.setAdapter(new MyImageAdapter(this));
ImageView imageview = (ImageView)findViewById(R.id.GalleryView);
Button btnnext = (Button)findViewById(R.id.btn_nxt);
Log.i("counter", ""+counter);
btnnext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//for(i=0;i<=5;i++){
mGridView.setAdapter(new MyImageAdapter(getApplicationContext()));
Log.i("counter", ""+counter);
//}
// TODO Auto-generated method stub
//mGridView.setAdapter(new MyImageAdapter(getApplicationContext()));
//Toast.makeText(MyGridView.this, "No Images", Toast.LENGTH_SHORT).show();
}
}
);
}
}
class MyImageAdapter extends BaseAdapter{
private Context mContext;
ImageView imageview;
int counter;
public MyImageAdapter(Context c){
mContext = c;
}
public MyImageAdapter(OnClickListener onClickListener) {
// TODO Auto-generated constructor stub
}
@Override
public int getCount() {
// TODO Auto-for(i = 6;i<=counter;i++) {generated method stub
//counter = mThumbsIds.length;
//System.out.println("Counter = "+counter);
return 5;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
imageview = new ImageView(mContext);
imageview.setLayoutParams(new GridView.LayoutParams(85,85));
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setPadding(8, 8, 8, 8);
}
else{
imageview = (ImageView) convertView;
}
//int[] mThumbIds = null;
imageview.setImageResource(mThumbsIds[position]);
return imageview;
//return null;
}
private Integer[] mThumbsIds = {
R.drawable.image1,R.drawable.image2,
R.drawable.image3,R.drawable.image4,
R.drawable.image5,R.drawable.icon,
R.drawable.icon,R.drawable.icon,
R.drawable.icon};
}
请帮我解决这个问题。