无论我们将tab2设置为默认选项卡,android始终都会调用android第一个tab意图oncreate(android first tab intent oncreate always called regardless we set tab2 as default tab)
以下是具有意向数据的选项卡示例。
在调试过程中,我发现总是在第一个选项卡时,我们在标签主机中添加下面的选项卡
tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(new Intent(this, List1.class)));
oncreate方法的“List1”意图被调用,无论它是我们的当前标签或不,即使如果我将tab2定义为当前标签如何解决此问题?
public class Tabs3 extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(new Intent(this, List1.class))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("photo list") .setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); // This tab sets the intent flag so that it is recreated each time // the tab is clicked. tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("destroy") .setContent(new Intent(this, Controls2.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); } }
Following is the example of tabs with intent data.
While debugging i found that always when first tab we add in tab host in our case following tab
tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(new Intent(this, List1.class)));
oncreate method of "List1" intent get called regardless it is our current tab or not even if if i define tab2 as a current tab how to fix this ?
public class Tabs3 extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(new Intent(this, List1.class))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("photo list") .setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); // This tab sets the intent flag so that it is recreated each time // the tab is clicked. tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("destroy") .setContent(new Intent(this, Controls2.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); } }
原文:https://stackoverflow.com/questions/2370630
最满意答案
您应该使用
group by
expression name 。select -- locate( '.', ip, locate( '.', ip, locate( '.', ip ) + 1 ) + 1 ) as l, substr( ip, 1, locate( '.', ip , locate( '.', ip , locate( '.', ip ) + 1 ) + 1 ) - 1 ) as subip, count(ip) as count from ip_list group by ( subip ) order by count desc ;
编辑1 :
不需要使用locate
。SUBSTR_INDEX
可用于过滤IP的子集。示例 :
select substring_index( ip, '.', 3 ) as subip , count(ip) as count from ip_list group by ( subip ) order by count desc
请参阅文档 :
- MySQL:SUBSTR(str,pos,len)
- 从字符串str返回一个子串len个字符,从位置pos开始。
- MySQL:SUBSTRING_INDEX(str,delim,count)
- 在分隔符delim的计数出现之前,从字符串str返回子字符串。
You should have used
group by
expression name.select -- locate( '.', ip, locate( '.', ip, locate( '.', ip ) + 1 ) + 1 ) as l, substr( ip, 1, locate( '.', ip , locate( '.', ip , locate( '.', ip ) + 1 ) + 1 ) - 1 ) as subip, count(ip) as count from ip_list group by ( subip ) order by count desc ;
EDIT 1:
Use oflocate
is not required.SUBSTR_INDEX
can be used to filter the subset of IP's.Example:
select substring_index( ip, '.', 3 ) as subip , count(ip) as count from ip_list group by ( subip ) order by count desc
Refer to Documentation:
- MySQL: SUBSTR(str,pos,len)
- Return a substring len characters long from string str, starting at position pos.
- MySQL: SUBSTRING_INDEX(str,delim,count)
- Returns the substring from string str before count occurrences of the delimiter delim.
相关问答
更多-
如何获得使用Java在同一网络(子网)中连接的IP列表(How to get a list of IP connected in same network (subnet) using Java)[2022-05-29]
这应该在网络上的主机对ICMP软件包(ping)(> JDK 5)作出反应时运行: public void checkHosts(String subnet){ int timeout=1000; for (int i=1;i<255;i++){ String host=subnet + "." + i; if (InetAddress.getByName(host).isReachable(timeout)){ System.out.print ... -
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
在Python 3.3+中,您可以使用ipaddress模块: >>> import ipaddress >>> ipaddress.ip_address('192.0.43.10') in ipaddress.ip_network('192.0.0.0/16') True 如果您的Python安装超过3.3,您可以使用此回送 。 如果你想以这种方式评估很多 IP地址,你可能需要预先计算网络掩码,例如 n = ipaddress.ip_network('192.0.0.0/16') netw = int( ...
-
内部表示在系统之间是否一致,或者我是否需要对s_addr字段进行Endian-ness检查/更正? s_addr在所有平台上始终处于网络(大端)字节顺序。 是否存在CLASS_C_NETMASK,CLASS_B_NETMASK等行的标准宏,这比使用手动生成的掩码(即:0xFF000000,0x00FF0000等)更合适。 不,使用这样的宏也没有意义,因为子网掩码不是从一个网络固定到另一个网络。 您需要为代码提供实际的网络IP及其子网掩码(提示用户,查询操作系统等)。 然后,您可以计算子网的起始和结束IP以与 ...
-
aws ec2 describe-instances --filters "Name=subnet-id,Values=subnet-12345678" --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text 使用describe-instances 按subnet-id查询 通过PrivateIpAddress筛选结果 使用@Michael - sqlbot的建议: aws ec2 describe-network-in ...
-
比较两个ip子网(Compare two ip subnet)[2024-03-19]
bool checkForSubnetEquality(in_addr_t ipA, in_addr_t ipB, uint32_t subnetMask) { return (ipA & subnetMask) == (ipB & subnetMask); } bool checkForSubnetEquality(in_addr_t ipA, in_addr_t ipB, uint32_t subnetMask) { return (ipA & subnetMask) == (ipB & ... -
需要打破IP子网(Need to break down a IP subnet)[2023-01-10]
看看netaddr软件包。 它已经内置了对理解网络掩码的支持,并且能够生成任意期望长度的子网列表: >>> n = netaddr.IPNetwork('10.10.8.0/22') >>> list(n.subnet(24)) [IPNetwork('10.10.8.0/24'), IPNetwork('10.10.9.0/24'), IPNetwork('10.10.10.0/24'), IPNetwork('10.10.11.0/24')] >>> [str(sn) for sn in n.subne ... -
您应该使用group by expression name 。 select -- locate( '.', ip, locate( '.', ip, locate( '.', ip ) + 1 ) + 1 ) as l, substr( ip, 1, locate( '.', ip , locate( '.', ip , locate( '.', ip ) + 1 ) + ...
-
用于查找列表中的IP是否属于不同子网的Pythonic方法(Pythonic way to find if an IP in a list belongs to a different subnet)[2021-10-16]
这样的东西会起作用: from itertools import groupby ips = ['10.0.0.1', '10.0.0.2', '10.0.10.3', '10.0.0.4', '10.0.0.5'] def get_subnet(ip): return '.'.join(ip.split('.')[:3]) groups = {} # group ips by subnet for k, g in groupby(sorted(ips), key=get_subnet): ... -
尝试这个: BEGIN { FS="." ex = "false" split(address, ip, ".") } { split($0, range, "[-.]") for (i=1; i<5; i++) { if (ip[i] < range[i] || ip[i] > range[i+4]) break; else if ((ip[i] > range[i] && ip[i] < range[i+4] ...