- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 BaseActivity。我实现了一些方法,并在子 Activity 中使用了这个覆盖方法。这是 BaseActivity 类
public class BaseActivity extends FragmentActivity {
public static BaseActivity mThis;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_empty_menu);
mThis = this;
try {
IO.Options opts = new IO.Options();
opts.forceNew = true;
opts.reconnection = false;
socketConnectionShowDialog();
final io.socket.client.Socket socket = IO.socket("http://54e1755a.ngrok.io", opts);
socket.on(io.socket.client.Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject obj = new JSONObject();
try {
obj.put("host", "*********");
obj.put("entity", new DeviceManager(UApplication.getInstance()).getDeviceId());
socket.emit("initialize", obj);
} catch (JSONException e) {
e.printStackTrace();
}
}
}).on("onconnect", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject obj = (JSONObject) args[0];
Log.e("obj", obj.toString());
socketConnectionHideDialog();
}
}).on("onerror", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject obj = (JSONObject) args[0];
Log.e("obj", obj.toString());
socketConnectionOnError();
}
}).on("device", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject jsonObject = (JSONObject) args[0];
socketConnectionOnDevice(jsonObject);
}
}).on(io.socket.client.Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
}
});
socket.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
socketConnectionHideDialog();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
super.onSaveInstanceState(outState);
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
}
protected View getRootView() {
return this.getWindow().getDecorView().findViewById(android.R.id.content);
}
protected void socketConnectionShowDialog() {
}
protected void socketConnectionHideDialog() {
}
protected void socketConnectionOnDevice(JSONObject jsonObject) {
}
protected void socketConnectionOnError() {
}
}
这是子 Activity java 类
public class MainActivity extends BaseActivity {
private ImageView videoStatus;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoStatus = (ImageView) findViewById(R.id.video_status);
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
@Override
protected void socketConnectionHideDialog() {
super.socketConnectionHideDialog();
Log.e("socketConnectionHideDialog", "socketConnectionHideDialog");
}
@Override
protected void socketConnectionOnDevice(JSONObject jsonObject) {
super.socketConnectionOnDevice(jsonObject);
Log.e("socketConnectionOnDevice", "socketConnectionOnDevice");
}
@Override
protected void socketConnectionOnError() {
super.socketConnectionOnError();
Log.e("socketConnectionOnError", "socketConnectionOnError");
}
@Override
protected void socketConnectionShowDialog() {
super.socketConnectionShowDialog();
Log.e("socketConnectionShowDialog", "socketConnectionShowDialog");
initUniMedia();
}
private void initUniMedia() {
videoStatus.setVisibility(View.VISIBLE);
}
}
activity_main.xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<ImageView
android:id="@+id/video_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="@mipmap/pause_icon"
android:textColor="#ffffff"
android:textSize="24dp" />
</RelativeLayout>
我的覆盖功能工作完美,只有我在 View 的 setVisibility.in activity_main.xml 中有问题,当然包含此 View 我该如何解决我的问题?
最佳答案
super.onCreate(savedInstanceState);
调用之前调用的 socketConnectionShowDialog();
:videoStatus = (ImageView) findViewById(R.id.video_status);
也就是在实际初始化 View 之前调用 view.setVisiblility()
PS:在您的 BaseActivity
中,我将逻辑从 onCreat()
移动到 onStop()
在 onStart 中,您知道 onCreate 已完成并且您的所有 View 都已完成初始化
关于android - setVisibility 在 android 中为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42858378/
我有一个代码,当我单击 jButton 时,它应该设置为不可见,而另一个已设置为 FALSE 的 JButton 应该为 TRUE,setVisible(true) 不起作用。 buttonGrid[
我看到了一些关于这个的帖子,我明白了这个问题。但是怎么绕过去呢?我有 ListView 和可以展开的项目,但是一旦 View 消失,它就不会再可见,除非它有可用空间。如何创造这个空间? private
JFrame 在循环中无法正确显示。代码:- import javax.swing.*; import java.awt.event.*; import java.awt.*; import j
下面的代码应该重置框架gameFrame: private void reset() { moveCount = 0; gameFrame.setVisible(false);
请看下图来理解问题: 如您所见,有一个 RelativeLayout 包含一个自定义 View 和一个 LinearLayout。 在它们之间,还有另一个 View,Visibility 被设置为 G
我有一个 JScrollPane包含 JPanel然后包含一些自定义组件,它们是 JPanel 的扩展(它们都是同一类型)。此 JScrollPane 在包含 JFrame 之前设置为不可见显示。 当
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我是 JFrame 的新手,我正在尝试做一个项目,如果按“注销”按钮,则可以完美执行以下代码, public void actionlogout() { lButton.addActionLi
我试图隐藏除 1 之外的所有 jList,它是从 jcomboBox (cbLists) 的索引中获得的,它并没有真正隐藏 jLists,就像禁用而不是隐藏一样,我需要它隐藏所有内容,就像完全不可见一
你能帮我吗?我正在尝试创建一个菜单,只需按一下按钮即可显示项目。我想我应该使菜单项visible:false,然后在MainActivity中切换这个属性。但我做不到正确的事。我需要 3 个新菜单项。
我想知道,这样做会更有效率吗: setVisible(false) // if the component is invisible 或者像这样: if(isVisible()){
简单介绍一下我在做什么。 我根据用户登录的帐户类型授予不同的功能。 用户的帐户类型将通过 Firebase 数据库中的 Firebase 引用检索。如果您查看此图像,就会看到箭头指示。这是显示帐户类型
我在处理程序中隐藏了一个按钮(这是在我使其在应用程序的另一种状态下可见之后)。处理程序从正在运行的线程接收消息,然后更新 GUI。 问题是附近的(不是全部)按钮和 TextView 也从屏幕上消失了。
我有一个带有 jcheckbox 和 jtextfield 的 jframe(它有更多组件)。 我将标签设置为 setVisible(false),当复选框被选中时,它应该使标签可见。它确实如此,但您
这是我的布局:
我是 android 开发的新手。我在 LinearLayout 中包含一个网格,组成网格的每个项目都是一个按钮。当用户按下这些按钮中的任何一个时,我希望此 LinearLayout 不可见。 这是我
我在抽屉中使用 NavigationView 并且 Menu 中有一个项目具有指向 的 app:actionLayout 属性>LinearLayout 包含一个 TextView,并且 TextVi
我有一个 LinearLayout,我希望能够通过单击“更多详细信息”链接来显示/隐藏它。我通过调用来做到这一点 moreDetailsSection.setVisibility(View.VISIB
在 JavaFX 中,如果我有一个包含 2 个 VBox 元素的场景,并且每个 VBox 中都有多个 Label。 如果我将顶部的VBox设置为invisible,为什么底部的VBox不上移顶部的场景
所以我一直在论坛中寻找如何做到这一点,但我发现没有任何效果。当我在图像按钮上调用 setVisibility() 时,该按钮不受影响。下面是 onCreate 方法中的代码,当我运行应用程序时,两个按
我是一名优秀的程序员,十分优秀!