开发者

how to display the next images by clicking on the "next" button

I am trying to display the image by clicking on the "next" button but this code doesn't work.

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,
 开发者_JAVA技巧       R.drawable.image3,R.drawable.image4,
        R.drawable.image5,R.drawable.icon,
        R.drawable.icon,R.drawable.icon,
        R.drawable.icon};
 }

Please help me out to correct this.


To refresh grid view see this search result

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜