LongClick在标签 [英] LongClick in tabs
本文介绍了LongClick在标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有我们可以在标签中添加setOnLongClickListener一种方式?或者有没有其他的办法,其中一个标签,并进行不同的活动上点击时当同一选项卡上单击长我可以调用一个活动?
公共类HelloTabWidget扩展TabActivity {
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main); 资源解析度= getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec规范;
意图意图; //创建一个Intent来启动一个活动的标签(重复使用)
意图=新意图()setClass(这一点,ArtistsActivity.class)。 //初始化则tabspec每个选项卡,并把它添加到TabHost
规格= tabHost.newTabSpec(艺术家)。setIndicator(艺术家
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(意向);
tabHost.addTab(规范);
tabHost.setOnLongClickListener(新OnLongClickListener(){ @覆盖
公共布尔onLongClick(视图v){
// TODO自动生成方法存根
////意向书I =新意图(getApplicationContext(),LongClickStuff.class);
// startActivity(ⅰ);
//返回true;
Toast.makeText(getApplicationContext(),走进长按Toast.LENGTH_LONG).show();
返回false;
} });
//做其他选项卡相同
意图=新意图()setClass(这一点,AlbumsActivity.class)。
规格= tabHost.newTabSpec(专辑)。setIndicator(相册,
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(意向);
tabHost.addTab(规范); 意图=新意图()setClass(这一点,SongsActivity.class)。
规格= tabHost.newTabSpec(诗经)。setIndicator(诗经,
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(意向);
tabHost.addTab(规范); tabHost.setCurrentTab(2);
}
}
解决方案
测试和认证,其中0是选项卡的索引要长点:
tabHost.getTabWidget()。getChildAt(0).setOnLongClickListener(新OnLongClickListener(){
公共布尔onLongClick(视图v){
Toast.makeText(getApplicationContext(),长按,1).show();
返回true;
}
});
Is there a way we can add setOnLongClickListener in Tabs?? Or is there any other way where i can call one activity when clicked on a tab and a different activity when long clicked on the same tab??
public class HelloTabWidget extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setOnLongClickListener(new OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
//// Intent i=new Intent(getApplicationContext(),LongClickStuff.class);
// startActivity(i);
// return true;
Toast.makeText(getApplicationContext(), "into long click", Toast.LENGTH_LONG).show();
return false;
}
});
// Do the same for the other tabs
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
解决方案
Tested and verified where "0" is the index of the tab to be long clicked:
tabHost.getTabWidget().getChildAt(0).setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(getApplicationContext(), "long click", 1).show();
return true;
}
});
这篇关于LongClick在标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文