在Windows 10上使用Convert.ToDouble(' Infinity')避免FormatException

时间:2015-10-13 21:30:15

标签: .net windows windows-10

我如何解析" Infinity"在Windows 10上?我在使用RowFilter时碰到了这个: e.g。

Fragment class/activity:

`public class BankingFrag extends Fragment  {
    GridView gv;

    public static String[] selections = {"Statements, Transfer, E-Transfer, Picture-Deposit "};
    public static int[] imgs = {R.drawable.ic_description_black_24dp, R.drawable.ic_swap_horiz_black_24dp
                            , R.drawable.ic_email_black_24dp, R.drawable.ic_camera_alt_black_24dp};

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container
            , @Nullable Bundle savedInstanceState) {


        View v = inflater.inflate(R.layout.fragment_banking, container, false);
        gv = (GridView) v.findViewById(R.id.gridView);
        gv.setAdapter(new CustomImageAdapter(v.getContext(),selections,imgs));


        return v;
    }


}`

fragment_banking.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/activity_horizontal_margin">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/CHQ"
            android:layout_marginLeft="16dp"
            android:textSize="25sp"
           />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4,302.98"
            android:ems="10"
            android:id="@+id/chqText"
            android:layout_marginLeft="30dp"
            android:textSize="20sp"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/activity_horizontal_margin">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/SAV"
            android:layout_marginLeft="16dp"
            android:textSize="25sp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="10,002.56"
            android:ems="10"
            android:id="@+id/savText"
            android:layout_marginLeft="30dp"
            android:textSize="20sp"/>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >

        <GridView android:id="@+id/gridView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="80dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="1dp"
            android:stretchMode="columnWidth"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:gravity="center" />

    </RelativeLayout>


</LinearLayout>

gridview_item.xml: 

    <?xml version="1.0" encoding="utf-8"?>
<!-- the parent view -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:padding="5dp" >

    <!-- the ImageView for the icon -->
    <ImageView android:id="@+id/ivIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="1dp"
        android:contentDescription=""
        android:scaleType="fitXY"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <!--  the TextView for the title -->
    <TextView android:id="@+id/opTitle"
        android:layout_below="@id/ivIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:gravity="center_horizontal"
        android:layout_centerHorizontal="true"
        android:textAppearance="@android:style/TextAppearance.Medium" />
</RelativeLayout>

The custom adapter class, CustomImageAdpater.java

    package com.comp3717lab.matt.bankingapp;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class CustomImageAdapter extends BaseAdapter{

    String [] result;
    Context context;
    int [] imageId;
    private static LayoutInflater inflater=null;
    public CustomImageAdapter(Context c, String[] prgmNameList, int[] prgmImages) {
        // TODO Auto-generated constructor stub
        result=prgmNameList;
        context=c;
        imageId=prgmImages;
        inflater = ( LayoutInflater )context.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return result.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class Holder
    {
        TextView text;
        ImageView img;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        View rowView;

        rowView = inflater.inflate(R.layout.gridview_item, null);
        holder.text=(TextView) rowView.findViewById(R.id.opTitle);
        holder.img=(ImageView) rowView.findViewById(R.id.ivIcon);

        holder.text.setText(result[position]);
        holder.img.setImageResource(imageId[position]);

        rowView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
            }
        });

        return rowView;
    }

}

Thanks for any help! PS new at android dev

此代码适用于Windows 7/8,但在Windows 10上使用FormatException中断。

1 个答案:

答案 0 :(得分:1)

无限符号是特定于文化的。看来默认(us-en)文化使用的符号在Windows 8和10之间发生了变化。我不知道如何为{{1} rowFilter = "[ColumnName] = 'Infinity'" 指定InvariantCulture表达式:它似乎假设RowFilter。上面的CurrentCulture表达式适用于RowFilter的{​​{1}}:

PositiveInfinitySymbol