开发者社区> 问答> 正文

怎样在baseAdapter继承的listview中实现点击一个item就跳转到另一个activity

我想问一下怎样在baseAdapter继承的listview中实现点击一个item就跳转到另一个activity呢?

这是我的源码

package com.example.ct;


 import com.ct.view.ContactlistData;

 import android.app.Activity;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.View.OnClickListener;
 import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;




 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.BaseAdapter;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;


 public class Contactlistview extends Activity{
 private ListView lv;
 private OnItemClickListener itemClick;
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.contact_listview);
 lv=(ListView)findViewById(R.id.lv);
 lv.setAdapter(adapter); 
 }
 private BaseAdapter adapter=new BaseAdapter() { 
 private ContactlistData[] data=new ContactlistData[]{
 new ContactlistData("img1","dec img1",R.drawable.img1),
 new ContactlistData("img3","dec img3",R.drawable.img3),
 new ContactlistData("img6","dec img6",R.drawable.img6),

 };

 @Override
 public View getView(int position, View converView, ViewGroup parent) {
 ViewHolder viewHolder=null;
 LinearLayout ll=null;
 if(converView!=null)
 {
 ll=(LinearLayout) converView;
 }else{
 ll=(LinearLayout) LayoutInflater.from(Contactlistview.this).inflate(R.layout.contact, null);

 }
 ContactlistData data = getItem(position);

 ImageView icon=(ImageView) ll.findViewById(R.id.icon);
 TextView name=(TextView)ll.findViewById(R.id.name);
 TextView dec=(TextView)ll.findViewById(R.id.dec);

 icon.setImageResource(data.iconId);
 name.setText(data.name);
 dec.setText(data.dec);

 return ll;
 }

 @Override
 public long getItemId(int position) {

 return position;
 }

 @Override
 public ContactlistData getItem(int position) {

 return data[position];
 }

 @Override
 public int getCount() {

 return data.length;
 }
 };

 } 

展开
收起
爵霸 2016-06-02 10:01:41 2663 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载