我想问一下怎样在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;
}
};
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。