onListItemClick是没有得到所谓的ListActivity [英] onListItemClick is not getting called on ListActivity

查看:113
本文介绍了onListItemClick是没有得到所谓的ListActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的应用程序,我想显示使用ListActivity YouTube的缩略图列表

I have a small application, and I am trying to display list of youtube thumbnails using the ListActivity

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看起来像这样

The xml looks like this

<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调用。可否请你让我知道,如果我做任何错误?

I am not able to get the onListItemClick invoked. Could you please let me know if I am making any mistake?

更新1/17

当我点击没有任何反应,但我看到这在日志中

When I click nothing happens but I see these in logs

四月1号至18日:09:32.030:W /跟踪(973):从nativeGetEnabledTags意外的值:0

01-18 04:09:32.030: W/Trace(973): Unexpected value from nativeGetEnabledTags: 0

推荐答案

在我的的ListView 我有一个可点击的TextView 并点击的ImageView onListItemClick ,我没有工作,因为我有列表行不止一个可点击的项目。因此,我所做的是我实施 onClickListener 在我的 getView()适配器。这是我的code:

In my ListView I have an clickable TextView and clickable ImageView. onListItemClick didn't work for me since I have more than one clickable items in the list row. So what I did is i implemented onClickListener in my getView() for the adapter. Here is my code:

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 。否则的另一种选择是延长活动类的<​​code> MainActivity 然后再去做。

It happens since we have more than one clickable item and we are trying to use the ListActivity. Else the other option is to extend Activity class for your MainActivity and then do it.

这篇关于onListItemClick是没有得到所谓的ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆