android-在ListActivity上未调用onListItemClick

android-在ListActivity上未调用onListItemClick,第1张

概述我有一个小型应用程序,我正在尝试使用ListActivity显示youtube缩略图列表publicclassResultListActivityextendsListActivity{...........@OverrideprotectedvoidonCreate(BundlesavedInstanceState){loadData();------}privatevoidloadData(fina

我有一个小型应用程序,我正在尝试使用ListActivity显示youtube缩略图列表

public class ResultListActivity extends ListActivity {...........@OverrIDe    protected voID onCreate(Bundle savedInstanceState) {loadData();------}private voID loadData(final String searchquery) {        AsyncTask<Object, VoID, List<YouTubeVIDeos>> asyncTask = new AsyncTask<Object, VoID, List<YouTubeVIDeos>>() {.....}/** {@inheritDoc} */    @OverrIDe      protected voID onListItemClick(ListVIEw l, VIEw v, int pos, long ID) {          super.onListItemClick(l, v, pos, ID);        Log.d("test","InsIDe onListItemClick");}

xml看起来像这样

<ListVIEw        androID:ID="@androID:ID/List"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_centerHorizontal="true" >    </ListVIEw>   <ImageVIEw    androID:ID="@+ID/imageVIEw1"     androID:layout_height="wrap_content"    androID:layout_wIDth="100dp"     androID:focusable="false"    androID:focusableIntouchMode="false"    ></ImageVIEw>

适配器:

public class ResultVIEwAdapter extends BaseAdapter {@OverrIDe    public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {ImageVIEw imageVIEw = (ImageVIEw) row.findVIEwByID(R.ID.imageVIEw1);        imageVIEw.setimageDrawable(torvIDeo.getDrawable());        return row;}...}

我无法调用onListItemClick.如果我有任何错误,请告诉我吗?

更新1/17

当我单击时,什么也没有发生,但是我在日志中看到了这些

01-18 04:09:32.030:W / Trace(973):nativeGetEnabledTags中的意外值:0

解决方法:

在我的ListVIEw中,我有一个可单击的TextVIEw和可单击的ImageVIEw. onListItemClick不适用于我,因为列表行中有多个可点击项.因此,我所做的是在适配器的getVIEw()中实现了onClickListener.这是我的代码:

public class SimpleArrayAdapter extends ArrayAdapter<String>{private LayoutInflater mInflater;private String[] mStrings;private TypedArray mIcons;private int mVIEwResourceID;public SimpleArrayAdapter(Context context, int textVIEwResourceID, String[] names, TypedArray icons) {    super(context, textVIEwResourceID, names);    // Todo auto-generated constructor stub    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    mStrings = names;    mIcons = icons;    mVIEwResourceID = textVIEwResourceID;}public int getCount(){    return mStrings.length;}public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent){    convertVIEw = mInflater.inflate(mVIEwResourceID, null);    ImageVIEw iv = (ImageVIEw)convertVIEw.findVIEwByID(R.ID.option_icon);    iv.setimageDrawable(mIcons.getDrawable(position));    iv.setTag("colorChooserClicked");    iv.setonClickListener( new OnClickListener() {        int pos = position;        @OverrIDe        public voID onClick(VIEw v) {            // Todo auto-generated method stub            Log.v("text", "Image clicked, row %d"+pos);        }    });    TextVIEw tv = (TextVIEw)convertVIEw.findVIEwByID(R.ID.textvIEw01);    tv.setText(mStrings[position]);    tv.setTag("textVIEwClicked");    tv.setonClickListener(new OnClickListener() {        int textpos = position;        @OverrIDe        public voID onClick(VIEw v) {            // Todo auto-generated method stub            Log.v("text", "Title clicked  %s"+mStrings[textpos]);        }    });    return convertVIEw;}}

发生这种情况是因为我们有多个可点击的项目,并且我们正在尝试使用ListActivity.另一个选择是为MainActivity扩展Activity类,然后执行.

总结

以上是内存溢出为你收集整理的android-在ListActivity上未调用onListItemClick全部内容,希望文章能够帮你解决android-在ListActivity上未调用onListItemClick所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1095771.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存