gpt4 book ai didi

java - 为什么长按 PullToRefreshListView 不起作用?

转载 作者:行者123 更新时间:2023-11-30 03:29:30 25 4
gpt4 key购买 nike

我有一个 PullToRefreshListView - https://github.com/chrisbanes/Android-PullToRefresh

我需要长按一下。我的代码:

pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arr);
pullToRefreshView.setAdapter(adapter);
pullToRefreshView.setLongClickable(true);
pullToRefreshView.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
Log.d("privet ia long click", "yes");
return true;
}
});

但它不起作用。为什么?

最佳答案

检查与此库一起给出的示例并检查以下代码(此代码仅来自此库的示例代码):

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pulltorefresh);

mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);

// Set a listener to be invoked when the list should be refreshed.
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);

// Update the LastUpdatedLabel
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);

// Do work to refresh the list here.
new GetDataTask().execute();
}
});
// Add an end-of-list listener
mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() {

@Override
public void onLastItemVisible() {
Toast.makeText(PullToRefresh.this, "End of List!", Toast.LENGTH_SHORT).show();
}
});

ListView actualListView = mPullRefreshListView.getRefreshableView();

// Need to use the Actual ListView when registering for Context Menu
registerForContextMenu(actualListView);

mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));

mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);

/**
* Add Sound Event Listener
*/
SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this);
soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);
soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);
soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);
mPullRefreshListView.setOnPullEventListener(soundListener);

// You can also just use setListAdapter(mAdapter) or
// mPullRefreshListView.setAdapter(mAdapter)
actualListView.setAdapter(mAdapter);
}

在上面的代码列表中使用如下

ListView actualListView = mPullRefreshListView.getRefreshableView();

所以在实现这个之后你可以在它上面使用 longpresslistener..

actualListView.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
Log.d("privet ia long click", "yes");
return true;
}
});

希望它对您有所帮助,您明白了...干杯!

关于java - 为什么长按 PullToRefreshListView 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com