android – 在点击列表视图项目上启动新活动

我需要一些帮助才能在listview项中进行简单的单击以打开一个新的Activity.我在这里看到了很多这样的问题,但没有人帮助过我.

public class CustomListView extends ListActivity {

    private EfficientAdapter adap;
    ...

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        adap = new EfficientAdapter(this);
        setListAdapter(adap);


    }


    @Override
    protected void onListItemClick(ListView l,View v,int position,long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l,v,position,id);


        startActivity(new Intent(CustomListView.this,next.class));
    }


    public static class EfficientAdapter extends BaseAdapter implements Filterable {
        private LayoutInflater mInflater;
        private Bitmap mIcon1;
        private Context context;

        public EfficientAdapter(Context context) {
            // Cache the LayoutInflate to avoid asking for a new one each time.
            mInflater = LayoutInflater.from(context);
            this.context = context;
        }

        public View getView(final int position,View convertView,ViewGroup parent) {

            ViewHolder holder;


            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.adaptor_content,null);


                convertView.setOnClickListener(new OnClickListener() {
                    private int pos = position;
                    @Override
                    public void onClick(View v) {


                    }
                });



            convertView.setTag(holder);
            }else{
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
            }


            return convertView;
        }

        ...
    }
}

我还尝试在CustomListView类中添加onCreate方法中的下一个代码,但它也不起作用

ListView lv = getListView();

// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
  public void onItemClick(AdapterView
最佳答案
从CustomListView类中删除onListItemClick(),并将startActivity()方法放在convertView.setOnClickListener()中.

convertView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent(getApplicationContext(),two.class));
    }
});

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...