我在片段类中有方法.我想从主要活动中调用该方法,但我不想使用FragmentById(或)FragmentByTag.
我的片段方法:
public void setItemFromDrawer(String sourceTag, String destTag) {
//dosomething
}
Run Code Online (Sandbox Code Playgroud)
如何在不使用FragmentById(或)FragmentByTag的情况下从主活动调用上述方法?
java android android-fragments android-activity fragmentmanager
在我的应用程序中,我想从用户那里获得调查答案.所以,我决定将笑脸图像作为单选按钮.在Android上有可能吗?
例如,当用户触摸图像时,我将显示笑脸图像,它将像单选按钮一样被激活.一次,他们将被允许只选择一个.如果有人能指导我,我会很感激.
提前致谢!
我是 Android 新手,我想使用 IP 地址获取国家/地区名称和国家/地区代码。请任何人指导我。
获取IP的代码如下:
public String getLocalIpAddress() {
WifiManager wifiMgr = (WifiManager) getActivity().getSystemService(context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled()) {
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String wifiIpAddress = String.format("%d.%d.%d.%d",
(ip & 0xff),
(ip >> 8 & 0xff),
(ip >> 16 & 0xff),
(ip >> 24 & 0xff));
return wifiIpAddress;
}else{
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
Log.i("","111 inetAddress.getHostAddress(): "+inetAddress.getHostAddress());
//the condition …Run Code Online (Sandbox Code Playgroud)