我正在尝试使用 android 架构组件创建单个活动应用程序。我有一个片段 A,它有一些文本字段,当用户按下一个按钮时,我导航到片段 B,在该应用程序使用如下代码导航回 A 后,他上传并编辑一些图像:
findNavController().navigate(R.id.action_from_B_to_A, dataBundle)
当导航回 B 时,使用dataBundle. 问题在于所有文本字段都重置了,因为片段 A 基本上是从头开始重新创建的。我在某处读到谷歌的开发人员建议您可以将视图保存在 var 中,而不是每次都膨胀它。所以尝试这样做:
private var savedViewInstance: View? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return if (savedViewInstance != null) {
savedViewInstance
} else {
savedViewInstance =
inflater.inflate(R.layout.fragment_professional_details, container, false)
savedViewInstance
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,所有文本字段在导航回 A 时都会重置。我做错了什么?处理此类案件的正确方法是什么?
我正在制作一个数据收集应用程序,它有多个TextFields,比如超过 12 个。我正在使用一个表单键来验证所有这些。我想要所有文本字段的值,以便我可以将它们保存到 firestore。我该怎么做呢?这是我的代码:
import 'package:flutter/material.dart';
class MainForm extends StatefulWidget {
@override
_MainFormState createState() => _MainFormState();
}
class _MainFormState extends State<MainForm> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Center(
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Text('Enter information about PG Owner'),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
autofocus: true,
textCapitalization: TextCapitalization.words,
textAlignVertical: TextAlignVertical.center,
onTap: () {},
decoration: InputDecoration(
prefixIcon: Icon(Icons.face),
labelText: 'Enter Name of Owner',
border: OutlineInputBorder()),
),
),
Padding(
padding: …Run Code Online (Sandbox Code Playgroud) 我正在制作一个Qt Quick GUI应用程序(用于Windows),它使用OpenGL和C++来处理一些计算密集型的东西.我想在应用程序中嵌入python代码,以便做一些在python中相对容易的东西.
基本上,我只是希望c ++代码在python脚本中调用函数并让脚本完成工作,然后将返回的数据存储在变量(字符串或浮点数等)中以供进一步使用.我正在使用Qt创建器,我为MinGW编译器提供了python3 lib.我尝试了一些代码,但它看起来像python lib与Qt creator不完全兼容.使用pyqt这是一个好主意吗?什么是最好和最简单的方法呢?
编辑:这是我试过的基本代码,首先它给了我一个错误说,找不到pyconfig.h.然后我在我的python34 include目录中添加了一个INCUDEPATH.
#include "mainwindow.h"
#include <QApplication>
#include <boost/python.hpp>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
using namespace boost::python;
PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
Py_Initialize();
pName = PyString_FromString(argv[1]);
pModule = PyImport_Import(pName);
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, argv[2]);
if (PyCallable_Check(pFunc))
{
PyObject_CallObject(pFunc, NULL);
} else
{
PyErr_Print();
}
// Clean up
Py_DECREF(pModule);
Py_DECREF(pName);
Py_Finalize();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
我的简历:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += …Run Code Online (Sandbox Code Playgroud) 我正在测试这个插件的本地通知。我想在按下按钮时显示通知,这是我的代码:
FlatButton(
onPressed: () {
FlutterLocalNotificationsPlugin localNotifPlugin =
new FlutterLocalNotificationsPlugin();
var androidChannelSpecifics = AndroidNotificationDetails(
'default',
'Test App Notifications',
'Channel for default notifications from test app');
var iOSChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidChannelSpecifics, iOSChannelSpecifics);
localNotifPlugin.show(
0,
"Test Notificaiton",
"This is your test notification! :)",
platformChannelSpecifics);
},
child: Text("Show Notification"),
)
Run Code Online (Sandbox Code Playgroud)
这与插件的文档非常相似,但它不起作用,当我按下按钮时出现此错误:
D/EGL_emulation(24401): eglMakeCurrent: 0xa80053c0: ver 2 0 (tinfo 0xa8003360)
E/MethodChannel#dexterous.com/flutter/local_notifications(24401): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(24401): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null …Run Code Online (Sandbox Code Playgroud) 如何使用 将相机指向场景中的某个方向react-three-fiber?canvas 元素有一个相机道具,但它不提供设置角度的方法。
<Canvas camera={{ fov: 75, position: [-10, 45, 20]}}>
Run Code Online (Sandbox Code Playgroud) 我正在制作一个在Qt中复制文件的程序.我想知道我怎么可以用QProgressBar同bool QFile::copy(const QString & fileName, const QString & newName).这是否可以实现copy功能?可以暂停复制过程吗?
我是一个在 Qt Creator 中制作程序的初学者。我制作了一个应该使用 打开 Google Chrome 的按钮QtProcess::execute(),但出现以下错误:
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\build-QtMainLProject-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\moc_mainwindow.cpp:71: error: undefined reference to `MainWindow::buttonClickHandler()'`
:-1: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_openChrome_clicked()
{
QString exeloc = "F:\\Users\\Amol-2\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
QProcess::execute(exeloc);
}
Run Code Online (Sandbox Code Playgroud)
mainwindow.h:
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots: …Run Code Online (Sandbox Code Playgroud) 我坚持在本教程中将ROI粘贴到同一图像的另一个区域.当我尝试类似的东西时,Python会出现一个值错误:
img = cv2.imread(path, -1)
eye = img[349:307, 410:383]
img[30:180, 91:256] = eye
Run Code Online (Sandbox Code Playgroud)
Exeption:
Traceback (most recent call last):
File "test.py", line 13, in <module>
img[30:180, 91:256] = eye
ValueError: could not broadcast input array from shape (0,0,3) into shape (150,165,3)
Run Code Online (Sandbox Code Playgroud)
这可能是一个非常新的问题,但我无法通过谷歌搜索得出答案.这样做有其他numpy方法吗?
编辑:同样在教程中它没有指定如何输入坐标.例如:我可以输入我想要的区域的坐标:eye = img[x1:y1, x2:y2]或img[x1:x2, y1:y2].这让我很困惑.实际上我试图通过鼠标回调方法获取这些坐标,该方法打印了鼠标点击的位置.因此,坐标肯定来自图像内部.
我在我的应用程序中使用带有 BottomNavigationView 的导航组件。它在 4 个目的地之间切换,其中一个目的地包含一个片段,其中 RecyclerView 包含数百个项目。当我使用后退按钮时,RecyclerView 会恢复到之前的滚动位置。但是当我使用 BottomNavigationView 在目的地之间切换时,它不会恢复到之前的位置并重置到 RecyclerView 的顶部。这是我试图防止这种情况的代码
override fun onPause() {
super.onPause()
lastScrollPos = linearLayoutManager.findFirstVisibleItemPosition()
}
override fun onResume() {
super.onResume()
card_recyclerView.layoutManager?.scrollToPosition(lastScrollPos)
}
Run Code Online (Sandbox Code Playgroud)
这不起作用将 RecyclerView 恢复到正确位置的最佳方法是什么?