我使用这个库:chrisbanes/Android-PullToRefresh。
这是我的代码:
pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
ArrayList<String> myStringArray1 = new ArrayList<String>();
myStringArray1.add("something 1");
myStringArray1.add("something 2");
myStringArray1.add("something 3");
myStringArray1.add("something 4");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myStringArray1);
pullToRefreshView.setAdapter(adapter);
pullToRefreshView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// Do work to refresh the list here.
Log.e("myLogs", "Refresh");
}
});
当我尝试制作
时MyPullToRefreshListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
return false;
}
}
);
我有一个错误:
The method setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){}) is undefined for the type MyPullToRefreshListView
我可以以某种方式处理这种情况吗?
编辑1:
这是我的MyPullToRefreshListView类:
import android.content.Context;
import android.util.AttributeSet;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
public class MyPullToRefreshListView extends PullToRefreshListView {
public MyPullToRefreshListView(Context context) {
this(context, null);
}
public MyPullToRefreshListView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.listViewStyle);
}
public MyPullToRefreshListView(Context context, AttributeSet attrs, int defStyle) {
super(new ContextWrapperEdgeEffect(context), attrs);
}
}
答案 0 :(得分:2)
你应该遵循这个答案:How to Enable LongCLicks on my ListView?,它的写得非常好......
您的问题可能是您实现了错误的OnItemLongClickListener。在执行上述步骤之前,请尝试更改
new AdapterView.OnItemLongClickListener(){}
到
new View.OnItemLongClickListener(){}
//编辑:根据this source,您需要像以下一样实施:
//mPullRefreshListView.setOn
mPullRefreshListView.getRefreshableView()
.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Log.i("test", "item long cliked");
initiatePopupWindow(arg1, arg1.getTop(), arg1.getHeight());
return false;
}
});
所以关键是要调用 .getRefreshableView()