Java tutorial
/* * Copyright (C) 2011 Patrik kerfeldt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.viewflow; import com.ky.mainactivity.BaseActivity; import com.ky.mainactivity.NewDetailActivity; import com.ky.mainactivity.VedioDetailActivity; import com.ky.passenger.R; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.sax.StartElementListener; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.BaseAdapter; import android.widget.ImageView; public class ImageAdapter extends BaseAdapter { private Context mContext; private LayoutInflater mInflater; private int[] images; // ????,?? private String fromWhere = "news"; // int [] // imageArray={R.drawable.image_new_top_one,R.drawable.image_new_top_two,R.drawable.image_news_top_three}; public ImageAdapter(Context context, int[] image, String fromWhere) { mContext = context; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); images = image; this.fromWhere = fromWhere; } @Override public int getCount() { return Integer.MAX_VALUE; // ?getViewposition??? } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.news_image_item, null); } ((ImageView) convertView.findViewById(R.id.imgView)).setImageResource(images[position % images.length]); // text_Main.setText(strName[position % strName.length].toString()); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ?? if (fromWhere.equals("news")) { IntentNewsDetail(position); } else { IntentVedioDetail(position); } } }); return convertView; } // ? public void IntentNewsDetail(int position) { Intent intent = new Intent(); intent.setClass(mContext, NewDetailActivity.class); intent.putExtra("image_id", images[position % images.length]); intent.putExtra("title", strName[position % strName.length]); intent.putExtra("type", "news"); intent.putExtra("time", "2014-01-01"); intent.putExtra("description", des); intent.putExtra("src", ""); mContext.startActivity(intent); } // ?? public void IntentVedioDetail(int position) { Intent intent = new Intent(); intent.setClass(mContext, VedioDetailActivity.class); intent.putExtra("image_id", images[position % images.length]); intent.putExtra("title", strName[position % strName.length]); intent.putExtra("type", "vedio"); intent.putExtra("actor", "?"); intent.putExtra("description", des); intent.putExtra("director", ""); intent.putExtra("years", "19"); mContext.startActivity(intent); } String[] strName = { "??", "", "?" }; String des = "The Expendables????19801990" + "?????????????????"; // ? public void GetImage(int position) { Intent intent = new Intent(mContext, DetailActivity.class); Bundle bundle = new Bundle(); bundle.putInt("image_id", images[position % images.length]); intent.putExtras(bundle); mContext.startActivity(intent); } }