小编Ric*_*eri的帖子

处理屏幕旋转而不会丢失数据 - Android

我正在疯狂地弄清楚处理屏幕旋转的最佳方法是什么.我在这里阅读了数百个问题/答案,但我真的很困惑.

如何在重新创建活动之前保存myClass数据,这样我可以保留所有内容以重绘活动而无需另外无用的初始化?

有没有比parcelable更清洁,更好的方法?

我需要处理旋转,因为我想在横向模式下更改布局.

public class MtgoLifecounterActivity extends Activity {

    MyClass myClass;

    // Called when the activity is first created
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        If ( ?? first run...myClass == null ? ) {
            myClass = new MyClass();
        } else {
            // do other stuff but I need myClass istance with all values.
        }
        // I want that this is called only first time. 
        // then in case of rotation of screen, i want to restore …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-layout

41
推荐指数
6
解决办法
6万
查看次数

在评估对象时,IsNumeric抛出FormatException

我正在使用visual studio 2008开发用于Windows CE 6.0,紧凑框架的软件.

我有这个"奇怪的?" 使用isNumeric方法时出现问题.还有另一种更好的方法来完成这项工作吗?为什么让我成为例外?(事实上​​两个......都是FormatException类型)

谢谢

dim tmpStr as object = "Hello"
if isNumeric(tmpStr) then    // EXCEPTIONs on this line
    // It's a number
else
    // it's a string
end if
Run Code Online (Sandbox Code Playgroud)

.net vb.net compact-framework windows-ce visual-studio

2
推荐指数
1
解决办法
791
查看次数

尝试在.net中捕获

我正在寻找以下最有效和最优雅的方式:

  • 当Filename有效,损坏,不存在时,可以调用我的函数

该函数将反序列化XML对象.

主要可能的结果是:

  • 文件不存在
  • XML文件出错

如果我这样写,如果文件损坏,读者将不会被关闭.如果我在finally块中写入reader.close(),它会在给它分配值之前给出一个关于使用read的警告.

那么,我该如何解决这个问题?

Public Function DeSerializzaXML(ByVal FileName As String, ByRef tmpObj As Object, ByVal tmpClass As Type) As Boolean
    Dim serializer As XmlSerializer
    Dim reader As StreamReader
    Dim tmpSuccess As Boolean = False
    Try
        serializer = New XmlSerializer(tmpClass)
        reader = New StreamReader(FileName)
        tmpObj = serializer.Deserialize(reader)
        reader.Close()
        tmpSuccess = True
    Catch ex As Exception
        AggiungiRigaSuFile(ErroriPath, FileName + ", " + ex.Message, Configurazione.DiagnosticaOff, True)
    Finally

    End Try

    Return tmpSuccess
End Function
Run Code Online (Sandbox Code Playgroud)

.net vb.net error-handling try-catch

0
推荐指数
1
解决办法
2104
查看次数