English 中文(简体)
扩展适应器 观点
原标题:Extending AdapterView

i m 试图(为了学习目的)自己执行简单的调试器,其中物品来自基本调试器(来自 s样本的Image Adapter)。

实际守则就是这样:

    public class MyAdapterView extends AdapterView<ImageAdapter> implements AdapterView.OnItemClickListener{
    private ImageAdapter mAdapter;
    public MyAdapterView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initThings();
    }
    private void initThings(){
        setOnItemClickListener(this);
    }
    @Override
    public ImageAdapter getAdapter() {
        // TODO Auto-generated method stub
        return mAdapter;
    }
    @Override
    public void setAdapter(ImageAdapter adapter) {
        // TODO Auto-generated method stub
        mAdapter=adapter;
        requestLayout();
    }
    View obtainView(int position) {
        View child = mAdapter.getView(position, null, this);
        return child;
    }
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
     super.onLayout(changed, l, t, r, b);
        for(int i=0;i<mAdapter.getCount();i++){
            View child = obtainView(i);
            child.layout(10, 70*i, 70, 70);
            addViewInLayout(child, i, null, true);
        }
        this.invalidate();
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Log.d("MYEXAMPLES","Clicked an item!");
    }
}

这只是一个编织的主编,它只是展示了一个带有照片的假名单。 我知道,我可以先使用清单、GridView、Spinner等,但一米与甲状腺和一米的相对照,试图列举其中的一些内容。

Well, the question here is: Why is my onItemClick not firing?

Using the same ImageAdapter with a GridView, everything works ok, but when i use with above class, i get nothing. Inside AdapterView.java there is code for those click, longclick, etc events... so why can t i just fire them? Maybe i m misunderstanding basic things on how AdapterView works? Should I extend other base classes instead? And why?

希望事先就此找到更有经验的指导。

问题回答

如果看<代码>AdapterView来源,请看<代码>。 OnItemClickListener 采用以下方法:performItemClick:

public boolean performItemClick(View view, int position, long id) {
    if (mOnItemClickListener != null) {
        // ...
        mOnItemClickListener.onItemClick(this, view, position, id);
        return true;
    }
    return false;
}

但是,如果你在使用该方法的地方搜寻<代码>AdapterView的源头,你就会看到,在任何地方都打着这个灯!

事实上,如果你检查<代码>Gallery/code>的来源,例如,请看performItemClick,请在onSingleTapUp上查询。

如果你想要使用,你必须发现用户在某个地方点点击,并打电话<条码>。

不要延长“调子”一词,为什么要与“Adapter”一道尝试。 当你计算你的调任人的费用时,它忽略了以下方法。

getView(int position, View convertView,ViewGroup group) 

在上述方法中,你可以查阅清单清单中每个项目的布局,在此,你可以确定每个控制的所有辅助活动。

我在玩弄一些类似的东西,我正在使用你所期待的光线*<>/>。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...