当前位置:操作系统 > 安卓/Android >>

Android应用开发笔记 - 项目代码1

 FullImageActivity.java:
[java]
package com.example.prjandroid; 
 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.ImageView; 
 
public class FullImageActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        // TODO Auto-generated method stub  
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.full_img1); 
         
        Intent intent = getIntent(); 
        int position = intent.getExtras().getInt("id"); 
        ImageAdapter imgAdapter = new ImageAdapter(FullImageActivity.this); 
         
        ImageView imgView = (ImageView) findViewById(R.id.imgView1); 
        imgView.setImageResource(imgAdapter.mThumbIds[position]); 
    } 

 
    ImageAdapter.java: 
package com.example.prjandroid; 
 
import android.content.Context; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.GridView; 
import android.widget.ImageView; 
 
public class ImageAdapter extends BaseAdapter { 
    private Context mContext; 
     
    public Integer[] mThumbIds = { 
        R.drawable.emacs1, 
        R.drawable.emacs2, 
        R.drawable.emacs3, 
        R.drawable.emacs4, 
        R.drawable.emacs5, 
        R.drawable.emacs6, 
        R.drawable.emacs7, 
        R.drawable.emacs8, 
        R.drawable.emacs9, 
        R.drawable.emacs10, 
        R.drawable.emacs11, 
        R.drawable.emacs12, 
        R.drawable.emacs13, 
        R.drawable.emacs14, 
        R.drawable.emacs15 
    }; 
     
    public ImageAdapter(Context context) { 
        // TODO Auto-generated constructor stub  
        mContext = context; 
    } 
     
    @Override 
    public int getCount() { 
        // TODO Auto-generated method stub  
        return mThumbIds.length; 
    } 
 
    @Override 
    public Object getItem(int position) { 
        // TODO Auto-generated method stub  
        return position; 
    } 
 
    @Override 
    public long getItemId(int position) { 
        // TODO Auto-generated method stub  
        return 0; 
    } 
 
    @Override 
    public View getView(int position, View converView, ViewGroup parent) { 
        // TODO Auto-generated method stub  
        ImageView imgView = new ImageView(mContext); 
        imgView.setImageResource(mThumbIds[position]); 
        imgView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
        imgView.setLayoutParams(new GridView.LayoutParams(70, 70)); 
         
        return imgView; 
    } 
 

package com.example.prjandroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

public class FullImageActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.full_img1);
  
  Intent intent = getIntent();
  int position = intent.getExtras().getInt("id");
  ImageAdapter imgAdapter = new ImageAdapter(FullImageActivity.this);
  
  ImageView imgView = (ImageView) findViewById(R.id.imgView1);
  imgView.setImageResource(imgAdapter.mThumbIds[position]);
 }
}

    ImageAdapter.java:
package com.example.prjandroid;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
 private Context mContext;
 
 public Integer[] mThumbIds = {
  R.drawable.emacs1,
  R.drawable.emacs2,
  R.drawable.emacs3,
  R.drawable.emacs4,
  R.drawable.emacs5,
  R.drawable.emacs6,
  R.drawable.emacs7,
  R.drawable.emacs8,
  R.drawable.emacs9,
  R.drawable.emacs10,
  R.drawable.emacs11,
  R.drawable.emacs12,
  R.drawable.emacs13,
  R.drawable.emacs14,
  R.drawable.emacs15
 };
 
 public ImageAdapter(Context context) {
  // TODO Auto-generated constructor stub
  mContext = context;
 }
 
 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  return mThumbIds.length;
 }

 @Override
 public Object getItem(int position) {
  // TODO Auto-generated method stub
  return position;
 }

 @Override
 public long getItemId(int position) {
  // TODO Auto-generated method stub补充:移动开发 , Android ,

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,