我正在尝试将一个OnItemClickListener添加到android的coverflow应用程序,其中图像可以来回滚动,我要添加的部分是一个点击监听器,所以你可以点击其中一个图像然后转到另一项活动。我猜它的工作原理与你将OnItemClick添加到listview或填充图像的gridview相同。我知道之前已经提出过这个问题,但是这种情况有所不同。应用程序中还有其他代码没有意义。这里是代码来自http://www.inter-fuser.com/2010/01/android-coverflow-widget.html的地方,这个应用程序有以下四个java类:
CoverFlow.java //扩展CoverAbsSpinner并实现GestureDetector.OnGestureListener
CoverAdapterView.java //类扩展了Adapter和ViewGroup类
CoverAbsSpinner.java //此类扩展了CoverAdapterView.java
CoverFlowExample.java //扩展活动
奇怪的是,我在CoverAdapterView.java类中找到了下面显示的代码。将看起来像无用接口的东西放在课堂中间是没有意义的。并且它说"当单击此AdapterView中的项目时调用的回调方法。"
这是该方法的奥秘。你怎么打电话"这个?他们真的准备了OnItemClickListener吗?我会覆盖这件事还是什么?
并且由于此代码尚未理解?有谁知道这是什么目的?它是一个你必须实现或覆盖的接口。所以我质疑这个目的。
public interface OnItemClickListener {
/**
* Callback method to be invoked when an item in this AdapterView has
* been clicked.
* <p>
* Implementers can call getItemAtPosition(position) if they need
* to access the data associated with the selected item.
*
* @param parent The AdapterView where the click happened.
* @param view The view within the AdapterView that was clicked (this
* will be a view provided by the adapter)
* @param position The position of the view in the adapter.
* @param id The row id of the item that was clicked.
*/
void onItemClick(CoverAdapterView<?> parent, View view, int position, long id);
}
/**
* Register a callback to be invoked when an item in this AdapterView has
* been clicked.
*
* @param listener The callback that will be invoked.
*/
public void setOnItemClickListener(OnItemClickListener listener) {
mOnItemClickListener = listener;
}
/**
* @return The callback to be invoked with an item in this AdapterView has
* been clicked, or null id no callback has been set.
*/
public final OnItemClickListener getOnItemClickListener() {
return mOnItemClickListener;
}
/**
* Call the OnItemClickListener, if it is defined.
*
* @param view The view within the AdapterView that was clicked.
* @param position The position of the view in the adapter.
* @param id The row id of the item that was clicked.
* @return True if there was an assigned OnItemClickListener that was
* called, false otherwise is returned.
答案 0 :(得分:0)
coverFlow.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
switch(position)
{
case 0:
startActivity(new Intent(****.this,@@@@.class));
finish();
break;
case 1:
startActivity(new Intent(****.this, ####.class));
finish();
break;
case 2:
startActivity(new Intent(****.this, &&&&.class));
finish();
break;
}
}
});