大马资讯论坛 - 马来西亚中文资讯平台
标题:
[教学] Android getListView setOnItemLongClickListener longer duration display
[打印本页]
作者:
资讯王
时间:
2015-1-19 22:05
标题:
[教学] Android getListView setOnItemLongClickListener longer duration display
[教学] Android getListView setOnItemLongClickListener longer duration display
让Toast显示更久,只需加timer
Longer than Toast.LENGTH_SHORT and Toast.LENGTH_LONG
private Toast toast;
private static CountDownTimer timer =null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
// TODO Auto-generated method stub
if(toast != null)
{
timer.cancel();
toast.cancel();
}
toast= Toast.makeText(activity, oNewsItems.get(pos).news_desc, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
LinearLayout toastLayout = (LinearLayout) toast.getView();
TextView toastTV = (TextView) toastLayout.getChildAt(0);
toastTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, activity.getResources().getDimensionPixelSize(R.dimen.normal_font_size));
toast.show();
//Log.v("long clicked","pos: " + pos);
timer =new CountDownTimer(10000, 1000) //5sec
{
public void onTick(long millisUntilFinished)
{
toast.show();
}
public void onFinish()
{
toast.cancel();
}
}.start();
return true;
}
});
}
@Override
public void onListItemClick(ListView listView, View view, int position,
long id) {
if(toast != null)
{
timer.cancel();
toast.cancel();
}
Intent myIntent = new Intent(getActivity(), Frm_news_activity.class);
myIntent.putExtra("oNewsItem", oNewsItems.get(position));
startActivity(myIntent);
}
复制代码
欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/)
Powered by Discuz! X3.3