gpt4 book ai didi

android - 在选项卡中长按

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

有没有办法在标签中添加 setOnLongClickListener?或者有没有其他方法可以让我在单击选项卡时调用一个 Activity ,而在长时间单击同一选项卡时调用不同的 Activity ?

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);
}
}

最佳答案

经过测试和验证,其中“0”是要长按的选项卡的索引:

tabHost.getTabWidget().getChildAt(0).setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(getApplicationContext(), "long click", 1).show();
return true;
}
});

关于android - 在选项卡中长按,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6049180/

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