我需要一些帮助才能在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 clicklv.setonItemClickListener(new OnItemClickListener() { public voID onItemClick(AdapterVIEw> parent,VIEw vIEw,long ID) { startActivity(new Intent(CustomListVIEw.this,next.class)); }});
最佳答案从CustomListVIEw类中删除onListItemClick(),并将startActivity()方法放在convertVIEw.setonClickListener()中.convertVIEw.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { startActivity(new Intent(getApplicationContext(),two.class)); }});
总结 以上是内存溢出为你收集整理的android – 在点击列表视图项目上启动新活动全部内容,希望文章能够帮你解决android – 在点击列表视图项目上启动新活动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)