问:
ScrollView won't scroll, just cuts off the screen. How to fix?
I know this question has been asked, but I haven't found anything that works. Here's my xml:

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.myproject.SpendFragment">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/testBannerAdId">
    </com.google.android.gms.ads.AdView>

    <ScrollView
        android:layout_above="@id/adView"
        android:padding="@dimen/layoutPadding"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/alabamaButton"
                    android:contentDescription="Alabama"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/alaskaButton"
                    android:contentDescription="Alaska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/arizonaButton"
                    android:contentDescription="Arizona"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/arkansasButton"
                    android:contentDescription="Arkansas"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/californiaButton"
                    android:text="California"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/coloradoButton"
                    android:text="Colorado"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/connecticutButton"
                    android:text="Connecticut"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/delawareButton"
                    android:text="Delaware"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/floridaButton"
                    android:text="Florida"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/georgiaButton"
                    android:text="Georgia"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/hawaiiButton"
                    android:text="Hawaii"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/idahoButton"
                    android:text="Idaho"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/illinoisButton"
                    android:text="Illinois"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/indianaButton"
                    android:text="Indiana"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/iowaButton"
                    android:text="Iowa"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/kansasButton"
                    android:text="Kansas"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/kentuckyButton"
                    android:text="Kentucky"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/louisianaButton"
                    android:text="Louisiana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/maineButton"
                    android:text="Maine"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/marylandButton"
                    android:text="Maryland"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/massachusettsButton"
                    android:text="Massachusetts"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/michiganButton"
                    android:text="Michigan"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/minnesotaButton"
                    android:text="Minnesota"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/mississippiButton"
                    android:text="Mississippi"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/missouriButton"
                    android:text="Missouri"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/montanaButton"
                    android:text="Montana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nebraskaButton"
                    android:text="Nebraska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nevadaButton"
                    android:text="Nevada"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>
</code>```

In case it's relevant, here's the xml for the Main activity that the fragment's in:

```<code><android.support.design.internal.ScrimInsetsFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context="com.project.myproject.MainActivity" >

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_gravity="start"
            android:layout_width="@dimen/drawerWidth"
            android:layout_height="@dimen/drawerHeight"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

</android.support.design.internal.ScrimInsetsFrameLayout>
</code>```

There are more LinearLayouts within the LinearLayout, but you get the idea (more ImageButtons of states). I can see the little scroll thing on the right once, but it disappears and doesn't come back up. And in case it's relevant, there's space for the AdView on the bottom but it's just white space. I know that happens sometimes with a real ad, so I just figure the little placeholder ad will show up eventually.

As you can see, my ScrollView's height is match_parent and my LinearLayout's height is wrap_content. I have one child in the ScrollView. The ScrollView is wrapped in a RelativeLayout only because I want the AdView to be under the ScrollView. Is the issue is that there are multiple children in the outer LinearLayout? I've never had any issues with ScrollViews before so this is a little annoying haha.

Thank you!

EDIT: Here are two images. The only difference is that one has the little scrollbar on the side and the other doesn't. It disappears and never reappears on touch or movement. The blue squares are the placeholder images and there are four squares per inner LinearLayout.

答:
Here in your code + sign is missing in defining Id android:layout_above please add + sign and try once.
instead of this android:layout_above="@id/adView" go for android:layout_above="@+id/adView"

OR

Put your AdView below of ScrollView

Remove your line from ScrollView android:layout_above="@+id/adView"
and put this line to Adview widget

android:layout_below="@+id/scroll_view"

Body:
I know this question has been asked, but I haven't found anything that works. Here's my xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.project.myproject.SpendFragment">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/testBannerAdId">
    </com.google.android.gms.ads.AdView>

    <ScrollView
        android:layout_above="@id/adView"
        android:padding="@dimen/layoutPadding"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/alabamaButton"
                    android:contentDescription="Alabama"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/alaskaButton"
                    android:contentDescription="Alaska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>

                <ImageButton
                    android:id="@+id/arizonaButton"
                    android:contentDescription="Arizona"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/arkansasButton"
                    android:contentDescription="Arkansas"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/californiaButton"
                    android:text="California"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/coloradoButton"
                    android:text="Colorado"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/connecticutButton"
                    android:text="Connecticut"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/delawareButton"
                    android:text="Delaware"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/floridaButton"
                    android:text="Florida"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/georgiaButton"
                    android:text="Georgia"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/hawaiiButton"
                    android:text="Hawaii"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/idahoButton"
                    android:text="Idaho"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/illinoisButton"
                    android:text="Illinois"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/indianaButton"
                    android:text="Indiana"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/iowaButton"
                    android:text="Iowa"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/kansasButton"
                    android:text="Kansas"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/kentuckyButton"
                    android:text="Kentucky"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/louisianaButton"
                    android:text="Louisiana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/maineButton"
                    android:text="Maine"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/marylandButton"
                    android:text="Maryland"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/massachusettsButton"
                    android:text="Massachusetts"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/michiganButton"
                    android:text="Michigan"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/minnesotaButton"
                    android:text="Minnesota"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/mississippiButton"
                    android:text="Mississippi"
                    android:src="@drawable/placeholder2"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:weightSum="100"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/missouriButton"
                    android:text="Missouri"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/montanaButton"
                    android:text="Montana"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nebraskaButton"
                    android:text="Nebraska"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

                <ImageButton
                    android:id="@+id/nevadaButton"
                    android:text="Nevada"
                    android:src="@drawable/placeholder"
                    android:adjustViewBounds="true"
                    android:gravity="center"
                    android:layout_weight="25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

    </ScrollView>

</RelativeLayout>

In case it's relevant, here's the xml for the Main activity that the fragment's in:

<android.support.design.internal.ScrimInsetsFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context="com.project.myproject.MainActivity" >

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_gravity="start"
            android:layout_width="@dimen/drawerWidth"
            android:layout_height="@dimen/drawerHeight"
            app:menu="@menu/drawer_menu" />

    </android.support.v4.widget.DrawerLayout>

</android.support.design.internal.ScrimInsetsFrameLayout>

There are more LinearLayouts within the LinearLayout, but you get the idea (more ImageButtons of states). I can see the little scroll thing on the right once, but it disappears and doesn't come back up. And in case it's relevant, there's space for the AdView on the bottom but it's just white space. I know that happens sometimes with a real ad, so I just figure the little placeholder ad will show up eventually.

As you can see, my ScrollView's height is match_parent and my LinearLayout's height is wrap_content. I have one child in the ScrollView. The ScrollView is wrapped in a RelativeLayout only because I want the AdView to be under the ScrollView. Is the issue is that there are multiple children in the outer LinearLayout? I've never had any issues with ScrollViews before so this is a little annoying haha.

Thank you!

EDIT: Here are two images. The only difference is that one has the little scrollbar on the side and the other doesn't. It disappears and never reappears on touch or movement. The blue squares are the placeholder images and there are four squares per inner LinearLayout.


来源: stackexchange

问:
show all blogs with comments which are approved in codeigniter
there are two tables , blog and comments table. in blog table all blogs are stored an

Blog Table

```<code>----------------------------------------
id  | blog_name | date
----------------------------------------
1   |  abc   |   31/3/17
----------------------------------------
2   |  xyz   |   31/3/17
----------------------------------------
3   |  rbc   |   31/3/17
----------------------------------------
4   |  ert   |   31/3/17
----------------------------------------
</code>```

Comment Table

```<code>----------------------------------------
id  | comment |  blog_id | approved
----------------------------------------
1    | abc    |    1     |     0
----------------------------------------
2    | xyz    |    1     |     1
----------------------------------------
3    | rbc    |    2     |     0
----------------------------------------
4    | ert    |    4     |     1
----------------------------------------
</code>```

now i want to show results the  way .. that all blogs will show but with the count of comments with each blog.. but the comment count should be only for approved comments.. by default the approved comment is 0 means not approved but 1 means approved..the problem is if i join the two tables in where condition i write approved=1 then it shows only 2 blogs but i need to show all blogs with comments.. if any blog comment is not present in the comment table then it will show 0 count to me... please help me with this

im using this join.. this join not showing all blogs..

SELECT b.id,b.blog_name,COUNT(c.comment) as comment_count FROM blog b LEFT JOIN comment c ON b.id=c.blog_id WHERE c.approved=1 GROUP BY b.id

i want all blogs with comments.. it shows only approved comments related blogs..

答:
SELECT
blog.*,
COALESCE(COUNT(comments.id),0) AS comment_count

FROM blog
LEFT JOIN comments
ON comments.blog_id = blog.id AND comments.approved = 1

GROUP BY blog.id

ContentLicense: CC BY-SA 3.0

Body:
there are two tables , blog and comments table. in blog table all blogs are stored an

Blog Table

----------------------------------------
id  | blog_name | date
----------------------------------------
1   |  abc   |   31/3/17
----------------------------------------
2   |  xyz   |   31/3/17
----------------------------------------
3   |  rbc   |   31/3/17
----------------------------------------
4   |  ert   |   31/3/17
----------------------------------------

Comment Table

----------------------------------------
id  | comment |  blog_id | approved
----------------------------------------
1    | abc    |    1     |     0
----------------------------------------
2    | xyz    |    1     |     1
----------------------------------------
3    | rbc    |    2     |     0
----------------------------------------
4    | ert    |    4     |     1
----------------------------------------

now i want to show results the  way .. that all blogs will show but with the count of comments with each blog.. but the comment count should be only for approved comments.. by default the approved comment is 0 means not approved but 1 means approved..the problem is if i join the two tables in where condition i write approved=1 then it shows only 2 blogs but i need to show all blogs with comments.. if any blog comment is not present in the comment table then it will show 0 count to me... please help me with this

im using this join.. this join not showing all blogs..

SELECT b.id,b.blog_name,COUNT(c.comment) as comment_count FROM blog b LEFT JOIN comment c ON b.id=c.blog_id WHERE c.approved=1 GROUP BY b.id

i want all blogs with comments.. it shows only approved comments related blogs..


问:
How do I get rid of this TypeError when using python's click library?
So I thought using the python click library to build a simple command line tool would be pretty simple. It seems I am stuck on something that is just not clicking with me. I have the following code:

```<code>import click
import json
import os.path
import sys

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
@click.argument('title')
@click.argument('category')
@click.argument('tech')
@click.argument('problemNotes')
@click.argument('solutionNotes')

def hello(count, name, title, category, tech, problemNotes, solutionNotes):
    print(tech + problemNotes + solutionNotes)

if __name__ == '__main__':
    hello()
</code>```

This seems pretty straightforward. The CL tool should take in some options and arguments and then print some out. I then type the following at my terminal to invoke the tool:

```<code>python bugbook.py --name="steve" "Annoying stack bug" "compile bug" "xcode" "annoying" "get meowed"
</code>```

But I get the following error:

```<code>Traceback (most recent call last):
  File "bugbook.py", line 22, in <module>
    hello()
  File "/Library/Python/2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
TypeError: hello() got an unexpected keyword argument 'solutionnotes'
</code>```

Strange, I think. It seems this error is casued by:

```<code>if __name__ == '__main__':
    hello()
</code>```

Which actually invokes the main function fails to pass in the right parameters or something, but I have tried tinkering and just can't get it working. What obvious thing am i missing??

答:
Token Normalization

New in version 2.0.

Starting with Click 2.0, it’s possible to provide a function that is used for normalizing tokens. Tokens are option names, choice values, or command values. This can be used to implement case insensitive options, for instance.

In order to use this feature, the context needs to be passed a function that performs the normalization of the token. For instance, you could have a function that converts the token to lowercase:

```<code>CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())

@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--name', default='Pete')
def cli(name):
    click.echo('Name: %s' % name)
</code>```

Read more

Body:
So I thought using the python click library to build a simple command line tool would be pretty simple. It seems I am stuck on something that is just not clicking with me. I have the following code:

import click
import json
import os.path
import sys

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
@click.argument('title')
@click.argument('category')
@click.argument('tech')
@click.argument('problemNotes')
@click.argument('solutionNotes')

def hello(count, name, title, category, tech, problemNotes, solutionNotes):
    print(tech + problemNotes + solutionNotes)

if __name__ == '__main__':
    hello()

This seems pretty straightforward. The CL tool should take in some options and arguments and then print some out. I then type the following at my terminal to invoke the tool:

python bugbook.py --name="steve" "Annoying stack bug" "compile bug" "xcode" "annoying" "get meowed"

But I get the following error:

Traceback (most recent call last):
  File "bugbook.py", line 22, in <module>
    hello()
  File "/Library/Python/2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
TypeError: hello() got an unexpected keyword argument 'solutionnotes'

Strange, I think. It seems this error is casued by:

if __name__ == '__main__':
    hello()

Which actually invokes the main function fails to pass in the right parameters or something, but I have tried tinkering and just can't get it working. What obvious thing am i missing??

Body:
Token Normalization

New in version 2.0.

Starting with Click 2.0, it’s possible to provide a function that is used for normalizing tokens. Tokens are option names, choice values, or command values. This can be used to implement case insensitive options, for instance.

In order to use this feature, the context needs to be passed a function that performs the normalization of the token. For instance, you could have a function that converts the token to lowercase:

CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())

@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--name', default='Pete')
def cli(name):
    click.echo('Name: %s' % name)

Read more


问:
Converting FORTRAN to C / C++
As part of my Final Year Project, I need to convert some FORTRAN code into C or C++ (it doesn't matter which language as long as I can understand it, and I can understand C style languages).

I have discovered f2c, a program that allegedly converts FORTRAN to C, and tried to install it, following instructions, by saving a makefile.vc file on my drive and then doing

```<code>copy makefile.vc makefile
nmake
</code>```

(here is the part of the README file about installing f2c that is included in the f2c download page)

To compile f2c on Linux or Unix
  systems, copy makefile.u to makefile,
  edit makefile if necessary (see the
  comments in it and below) and type
  "make" (or maybe "nmake", depending on
  your system).

To compile f2c.exe on MS Windows
  systems with Microsoft Visual C++,

copy makefile.vc makefile  nmake

With other PC compilers, you may need
  to compile xsum.c with -DMSDOS (i.e.,
  with MSDOS #defined).

If your compiler does not understand
  ANSI/ISO C syntax (i.e., if you have a
  K&R C compiler), compile with
  -DKR_headers .

On non-Unix systems where files have
  separate binary and text modes, you
  may need to "make xsumr.out" rather
  than "make xsum.out".

I am running x64 bit version of Windows Vista and tried "nmake", but I get

'nmake' is not recognised as an internal or external command, operable program or batch file.

I downloaded Nmake15.exe after some searching but it doesn't work on x64 bit machines and apparently there is not version of it that does. So I downloaded the Windows SDK, after being told that would work, but it didn't change anything.

Where have I gone wrong in all this, if I have, and is there any way of converting that FORTRAN code into C or C++?

答:
f2c really is the way to go, provided you have F77 code.  If you have F90 or later then f2c won't help.  I've used f2c many many times with great success, so long as you remember the -a switch.

As an aside I would rate f2c as one of the all time great codes!

ContentLicense: CC BY-SA 2.5

Title: Converting FORTRAN to C / C++

Body:
As part of my Final Year Project, I need to convert some FORTRAN code into C or C++ (it doesn't matter which language as long as I can understand it, and I can understand C style languages).

I have discovered f2c, a program that allegedly converts FORTRAN to C, and tried to install it, following instructions, by saving a makefile.vc file on my drive and then doing

copy makefile.vc makefile
nmake

(here is the part of the README file about installing f2c that is included in the f2c download page)

To compile f2c on Linux or Unix
  systems, copy makefile.u to makefile,
  edit makefile if necessary (see the
  comments in it and below) and type
  "make" (or maybe "nmake", depending on
  your system).

To compile f2c.exe on MS Windows
  systems with Microsoft Visual C++,

copy makefile.vc makefile  nmake

With other PC compilers, you may need
  to compile xsum.c with -DMSDOS (i.e.,
  with MSDOS #defined).

If your compiler does not understand
  ANSI/ISO C syntax (i.e., if you have a
  K&R C compiler), compile with
  -DKR_headers .

On non-Unix systems where files have
  separate binary and text modes, you
  may need to "make xsumr.out" rather
  than "make xsum.out".

I am running x64 bit version of Windows Vista and tried "nmake", but I get

'nmake' is not recognised as an internal or external command, operable program or batch file.

I downloaded Nmake15.exe after some searching but it doesn't work on x64 bit machines and apparently there is not version of it that does. So I downloaded the Windows SDK, after being told that would work, but it didn't change anything.

Where have I gone wrong in all this, if I have, and is there any way of converting that FORTRAN code into C or C++?


问:
Event keypress jquery when match a special character
I'm trying to processing code when user type @ like facebook tag. When user type @abc, then event is processed. This is my code:

```<code>$("#content").keypress(function(e) {
          var tmp = $("#content").val();
          if(tmp =="@")
          {
            console.log("It working");
          }
        });
</code>```

UPDATING

Code like this:

```<code>$("#content").keypress(function(event) {
          var tmp  = $("#content").val();
          if(tmp.indexOf('@') !== -1)
          {
            console.log("It's working");
          }
        });
</code>```

It's working when i'm typing @ with anything charater, but when i type  (space), it also working, i try to stop event when user type (space) after @anything.

答:
best solution for this would be:

```<code>$("#content").keypress(function(e) {

    if (e.which == 64) {
        console.log("It working");
    }
});
</code>```

hope it helps!!!!!!

Body:
I'm trying to processing code when user type @ like facebook tag. When user type @abc, then event is processed. This is my code:

$("#content").keypress(function(e) {
          var tmp = $("#content").val();
          if(tmp =="@")
          {
            console.log("It working");
          }
        });

UPDATING

Code like this:

$("#content").keypress(function(event) {
          var tmp  = $("#content").val();
          if(tmp.indexOf('@') !== -1)
          {
            console.log("It's working");
          }
        });

It's working when i'm typing @ with anything charater, but when i type  (space), it also working, i try to stop event when user type (space) after @anything.

Body:
best solution for this would be:

$("#content").keypress(function(e) {

    if (e.which == 64) {
        console.log("It working");
    }
});

hope it helps!!!!!!


问:
Running multiple commands for npm test
I'm currently using a gulp task to test a project. This runs tasks using the following tools:

Karma (async)

Protractor (spawned process)

ESlint (using gulp-eslint)

HTMLHint (using gulp-htmlhint)

Stylelint (using gulp-postcss)

The task fails if any of these tasks failed.

All of these tools have perfectly fine cli interfaces. So I decided I'd like to run these tools using an npm test script instead.

For simplicitly let's say all tools run by simply invoking them without any flags. Then this can be done using:

```<code>{
  ...
  "scripts": {
    "test": "karma && protractor && eslint && htmlhint && stylelint"
  },
  ...
}
</code>```

However, this means that if karma fails, none of the other tools will run.

Is it possible to create a setup where all of these tools will run, but npm test will fail if any of the commands failed?

答:
npm-run-all can also handle this well

You can run multiple npm commands concurrently, continuing on error as follows:

npm-run-all --parallel --continue-on-error karma protractor eslint htmlhint stylelint

Options as written in the documentation:

```<code>-p, --parallel <tasks>   - Run a group of tasks in parallel.
                           e.g. 'npm-run-all -p foo bar' is similar to
                                'npm run foo & npm run bar'.
-c, --continue-on-error  - Set the flag to continue executing other tasks
                           even if a task threw an error. 'run-p' itself
                           will exit with non-zero code if one or more tasks
                           threw error(s).
</code>```

Title: Running multiple commands for npm test

Body:
I'm currently using a gulp task to test a project. This runs tasks using the following tools:

Karma (async)

Protractor (spawned process)

ESlint (using gulp-eslint)

HTMLHint (using gulp-htmlhint)

Stylelint (using gulp-postcss)

The task fails if any of these tasks failed.

All of these tools have perfectly fine cli interfaces. So I decided I'd like to run these tools using an npm test script instead.

For simplicitly let's say all tools run by simply invoking them without any flags. Then this can be done using:

{
  ...
  "scripts": {
    "test": "karma && protractor && eslint && htmlhint && stylelint"
  },
  ...
}

However, this means that if karma fails, none of the other tools will run.

Is it possible to create a setup where all of these tools will run, but npm test will fail if any of the commands failed?

Body:
npm-run-all can also handle this well

You can run multiple npm commands concurrently, continuing on error as follows:

npm-run-all --parallel --continue-on-error karma protractor eslint htmlhint stylelint

Options as written in the documentation:

-p, --parallel <tasks>   - Run a group of tasks in parallel.
                           e.g. 'npm-run-all -p foo bar' is similar to
                                'npm run foo & npm run bar'.
-c, --continue-on-error  - Set the flag to continue executing other tasks
                           even if a task threw an error. 'run-p' itself
                           will exit with non-zero code if one or more tasks
                           threw error(s).


问:
how do I stop timer from showing up in my other levels?
I made a game with 3 levels, easy,normal, and hard.

easy has 300 seconds before the timeup activity shows up,
normal has 600 seconds ,
hard has 900 seconds

for example, I chose easy but I lose so I went back to choose what level I would take next. I chose normal but the timer page for easy shows up.

how do I stop the TIMER from popping up in my other levels.

I am missing something

activity for level:

```<code>public class EasyAct extends AppCompatActivity {
    Button b1, b2, b3, b4;
    TextView tv1, tv2, tv3, tv4;
    int score =0;
    TriviaQuizHelper1 triviaQuizHelper1;
    TriviaQuestion1 currentQuestion;
    List<TriviaQuestion1> list;
    int qid = 0;
    int level = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_easy);

        tv1 = (TextView) findViewById(R.id.triviaQuestion);
        tv2 = (TextView) findViewById(R.id.triviTimer);
        b1 = (Button) findViewById(R.id.buttonA);
        b2 = (Button) findViewById(R.id.buttonB);
        b3 = (Button) findViewById(R.id.buttonC);
        b4 = (Button) findViewById(R.id.buttonD);
        tv3 = (TextView) findViewById(R.id.level);
        tv4 = (TextView) findViewById(R.id.score);
        CountDownTimer countDownTimer = new CountDownTimer(300 * 1000, 1000) {
            @Override
            public void onTick(long l) {
                tv2.setText("Timer:" + l / 1000 + " " + "sec");
            }

            @Override
            public void onFinish() {
                tv2.setText("TIME OUT");
                Intent intent = new Intent(EasyAct.this, timeup.class);
                startActivity(intent);
            }
        };
        countDownTimer.start();
        triviaQuizHelper1 = new TriviaQuizHelper1(this);
        SQLiteDatabase sqLiteDatabase = triviaQuizHelper1.getWritableDatabase();
        triviaQuizHelper1.allQuestion1();
        list = triviaQuizHelper1.getAllQuestion();
        currentQuestion = list.get(qid);
        view();
    }

    public void view() {
        tv1.setText(currentQuestion.getQuestion());
        b1.setText(" "+currentQuestion.getOpta());
        b2.setText(" "+currentQuestion.getOptb());
        b3.setText(" "+currentQuestion.getOptc());
        b4.setText(" "+currentQuestion.getOptd());
        tv3.setText("Level:"+level);
        tv4.setText("Score:"+score);
    }

    public void ButtonA(View view) {

        if (b1.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonB(View view) {
        if (b2.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonC(View view) {
        if (b3.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonD(View view) {
        if (b4.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    @Override
    public void onBackPressed() {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);
        finish();

    }
}
</code>```

答:
You can take countDownTimer as a global variable and cancel it as and when a new activity is started as follows :</p>

```<code>public class EasyAct extends AppCompatActivity {
        Button b1, b2, b3, b4;
        TextView tv1, tv2, tv3, tv4;
        int score =0;
        TriviaQuizHelper1 triviaQuizHelper1;
        TriviaQuestion1 currentQuestion;
        List<TriviaQuestion1> list;
        int qid = 0;
        int level = 1;
        private CountDownTimer countDownTimer; // declare as a global variable

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.act_easy);

            tv1 = (TextView) findViewById(R.id.triviaQuestion);
            tv2 = (TextView) findViewById(R.id.triviTimer);
            b1 = (Button) findViewById(R.id.buttonA);
            b2 = (Button) findViewById(R.id.buttonB);
            b3 = (Button) findViewById(R.id.buttonC);
            b4 = (Button) findViewById(R.id.buttonD);
            tv3 = (TextView) findViewById(R.id.level);
            tv4 = (TextView) findViewById(R.id.score);
            // initialize the timer
            countDownTimer = new CountDownTimer(300 * 1000, 1000) {
                @Override
                public void onTick(long l) {
                    tv2.setText("Timer:" + l / 1000 + " " + "sec");
                }

                @Override
                public void onFinish() {
                    tv2.setText("TIME OUT");
                    Intent intent = new Intent(EasyAct.this, timeup.class);
                    startActivity(intent);
                }
            };
            countDownTimer.start();
            triviaQuizHelper1 = new TriviaQuizHelper1(this);
            SQLiteDatabase sqLiteDatabase = triviaQuizHelper1.getWritableDatabase();
            triviaQuizHelper1.allQuestion1();
            list = triviaQuizHelper1.getAllQuestion();
            currentQuestion = list.get(qid);
            view();
        }

        public void view() {
            tv1.setText(currentQuestion.getQuestion());
            b1.setText(" "+currentQuestion.getOpta());
            b2.setText(" "+currentQuestion.getOptb());
            b3.setText(" "+currentQuestion.getOptc());
            b4.setText(" "+currentQuestion.getOptd());
            tv3.setText("Level:"+level);
            tv4.setText("Score:"+score);
        }

        public void ButtonA(View view) {

            if (b1.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    startActivity(intent);
                    countDownTimer.cancel();
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonB(View view) {
            if (b2.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonC(View view) {
            if (b3.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonD(View view) {
            if (b4.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        @Override
        public void onBackPressed() {
            Intent a = new Intent(Intent.ACTION_MAIN);
            countDownTimer.cancel();
            a.addCategory(Intent.CATEGORY_HOME);
            a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(a);
            finish();
        }
    }
</code>```

Body:
I made a game with 3 levels, easy,normal, and hard.

easy has 300 seconds before the timeup activity shows up,
normal has 600 seconds ,
hard has 900 seconds

for example, I chose easy but I lose so I went back to choose what level I would take next. I chose normal but the timer page for easy shows up.

how do I stop the TIMER from popping up in my other levels.

I am missing something

activity for level:

public class EasyAct extends AppCompatActivity {
    Button b1, b2, b3, b4;
    TextView tv1, tv2, tv3, tv4;
    int score =0;
    TriviaQuizHelper1 triviaQuizHelper1;
    TriviaQuestion1 currentQuestion;
    List<TriviaQuestion1> list;
    int qid = 0;
    int level = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_easy);

        tv1 = (TextView) findViewById(R.id.triviaQuestion);
        tv2 = (TextView) findViewById(R.id.triviTimer);
        b1 = (Button) findViewById(R.id.buttonA);
        b2 = (Button) findViewById(R.id.buttonB);
        b3 = (Button) findViewById(R.id.buttonC);
        b4 = (Button) findViewById(R.id.buttonD);
        tv3 = (TextView) findViewById(R.id.level);
        tv4 = (TextView) findViewById(R.id.score);
        CountDownTimer countDownTimer = new CountDownTimer(300 * 1000, 1000) {
            @Override
            public void onTick(long l) {
                tv2.setText("Timer:" + l / 1000 + " " + "sec");
            }

            @Override
            public void onFinish() {
                tv2.setText("TIME OUT");
                Intent intent = new Intent(EasyAct.this, timeup.class);
                startActivity(intent);
            }
        };
        countDownTimer.start();
        triviaQuizHelper1 = new TriviaQuizHelper1(this);
        SQLiteDatabase sqLiteDatabase = triviaQuizHelper1.getWritableDatabase();
        triviaQuizHelper1.allQuestion1();
        list = triviaQuizHelper1.getAllQuestion();
        currentQuestion = list.get(qid);
        view();
    }

    public void view() {
        tv1.setText(currentQuestion.getQuestion());
        b1.setText(" "+currentQuestion.getOpta());
        b2.setText(" "+currentQuestion.getOptb());
        b3.setText(" "+currentQuestion.getOptc());
        b4.setText(" "+currentQuestion.getOptd());
        tv3.setText("Level:"+level);
        tv4.setText("Score:"+score);
    }

    public void ButtonA(View view) {

        if (b1.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonB(View view) {
        if (b2.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonC(View view) {
        if (b3.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    public void ButtonD(View view) {
        if (b4.getText().toString().equals(" "+currentQuestion.getAnswer())){
            score+=300;
            if(qid<19){
                qid++;
                currentQuestion = list.get(qid);
                view();
            }else{
                Intent intent=new Intent(EasyAct.this,ResultWon.class);
                startActivity(intent);
                finish();
            }
        }
        else {
            Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
            Bundle b=new Bundle();
            b.putInt("xscore",score);
            intent.putExtras(b);
            startActivity(intent);
            finish();
        }
    }
    @Override
    public void onBackPressed() {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);
        finish();

    }
}

Body:
You can take countDownTimer as a global variable and cancel it as and when a new activity is started as follows :

public class EasyAct extends AppCompatActivity {
        Button b1, b2, b3, b4;
        TextView tv1, tv2, tv3, tv4;
        int score =0;
        TriviaQuizHelper1 triviaQuizHelper1;
        TriviaQuestion1 currentQuestion;
        List<TriviaQuestion1> list;
        int qid = 0;
        int level = 1;
        private CountDownTimer countDownTimer; // declare as a global variable

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.act_easy);

            tv1 = (TextView) findViewById(R.id.triviaQuestion);
            tv2 = (TextView) findViewById(R.id.triviTimer);
            b1 = (Button) findViewById(R.id.buttonA);
            b2 = (Button) findViewById(R.id.buttonB);
            b3 = (Button) findViewById(R.id.buttonC);
            b4 = (Button) findViewById(R.id.buttonD);
            tv3 = (TextView) findViewById(R.id.level);
            tv4 = (TextView) findViewById(R.id.score);
            // initialize the timer
            countDownTimer = new CountDownTimer(300 * 1000, 1000) {
                @Override
                public void onTick(long l) {
                    tv2.setText("Timer:" + l / 1000 + " " + "sec");
                }

                @Override
                public void onFinish() {
                    tv2.setText("TIME OUT");
                    Intent intent = new Intent(EasyAct.this, timeup.class);
                    startActivity(intent);
                }
            };
            countDownTimer.start();
            triviaQuizHelper1 = new TriviaQuizHelper1(this);
            SQLiteDatabase sqLiteDatabase = triviaQuizHelper1.getWritableDatabase();
            triviaQuizHelper1.allQuestion1();
            list = triviaQuizHelper1.getAllQuestion();
            currentQuestion = list.get(qid);
            view();
        }

        public void view() {
            tv1.setText(currentQuestion.getQuestion());
            b1.setText(" "+currentQuestion.getOpta());
            b2.setText(" "+currentQuestion.getOptb());
            b3.setText(" "+currentQuestion.getOptc());
            b4.setText(" "+currentQuestion.getOptd());
            tv3.setText("Level:"+level);
            tv4.setText("Score:"+score);
        }

        public void ButtonA(View view) {

            if (b1.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    startActivity(intent);
                    countDownTimer.cancel();
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonB(View view) {
            if (b2.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonC(View view) {
            if (b3.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        public void ButtonD(View view) {
            if (b4.getText().toString().equals(" "+currentQuestion.getAnswer())){
                score+=300;
                if(qid<19){
                    qid++;
                    currentQuestion = list.get(qid);
                    view();
                }else{
                    Intent intent=new Intent(EasyAct.this,ResultWon.class);
                    countDownTimer.cancel();
                    startActivity(intent);
                    finish();
                }
            }
            else {
                Intent intent=new Intent(EasyAct.this,ResultPlayAgain.class);
                countDownTimer.cancel();
                Bundle b=new Bundle();
                b.putInt("xscore",score);
                intent.putExtras(b);
                startActivity(intent);
                finish();
            }
        }
        @Override
        public void onBackPressed() {
            Intent a = new Intent(Intent.ACTION_MAIN);
            countDownTimer.cancel();
            a.addCategory(Intent.CATEGORY_HOME);
            a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(a);
            finish();
        }
    }


问:
Which dialect of C is Objective-C a "strict superset" of?
I frequently hear that Objective-C is a "strict superset" of the C programming language. There are several dialects/standards of C (ie. K&R, ANSI C, C90, C99, GNU extensions...); Objective-C was first developed in the early 1980s, so it has to predate these standards. However, Objective-C 2.0 is from around 2006 or 2007, so it could be based on a more modern C dialect. So, which "C" is Objective-C a superset of?</p>

答: What you're looking for isn't really defined. Objective C is usually thought of a strict superset of ANSI-C (which is the same as C90). However, Objective C isn't a standardized language or anything of that sort. It's description basically is "Take C, and add these features to it". It's therefore dependent on the particular compiler you're using.</p>


问:
Convert UTF-32 wide char to UTF-16 wide char in Linux for Supplementary Plane characters
We have a C++ application deployed on RHEL using ICU.

We have a situation where in we need to convert UChar* to wchar_t* on linux. We use u_strToWCS to perform the conversion.

```<code>#include <iostream>
#include <wchar.h>

#include "unicode/ustring.h"

void convertUnicodeStringtoWideChar(const UChar* cuniszSource,
                                    const int32_t cunii32SourceLength,
                                    wchar_t*& rpwcharDestination,
                                    int32_t& destCapacity)
{
  UErrorCode uniUErrorCode = U_ZERO_ERROR;

  int32_t pDestLength = 0;

  rpwcharDestination     = 0;
  destCapacity = 0;

  u_strToWCS(rpwcharDestination,
             destCapacity,
             &pDestLength,
             cuniszSource,
             cunii32SourceLength,
             &uniUErrorCode);

  uniUErrorCode = U_ZERO_ERROR;
  rpwcharDestination = new wchar_t[pDestLength+1];
  if(rpwcharDestination)
  {
    destCapacity = pDestLength+1;

    u_strToWCS(rpwcharDestination,
               destCapacity,
               &pDestLength,
               cuniszSource,
               cunii32SourceLength,
               &uniUErrorCode);

    destCapacity = wcslen(rpwcharDestination);
  }
} //function ends

int main()
{
    //                     a       ä       Š       €    (          )
    UChar input[20] = { 0x0061, 0x00e4, 0x0160, 0x20ac, 0xd87e, 0xdd29, 0x0000 };
    wchar_t * output;
    int32_t outlen = 0;
    convertUnicodeStringtoWideChar( input, 6, output, outlen );
    for ( int i = 0; i < outlen; ++i )
    {
        std::cout << std::hex << output[i] << "\n";
    }
    return 0;
}
</code>```

This works fine for characters entered upto 65535 (as UChar is implemented as uint16_t internally on linux). It fails to convert characters outside Basic Multilingual Plane (eg CJK Unified Ideographs Extension B)

Any ideas on how to perform the conversion?

Update 1: OK. I was looking at wrong directions. u_strToWCS works fine. The problem arises because I need to pass that wide string to a java application on windows using CORBA. Since wchar_t in linux is 32bit, I need to find a way to convert 32bit wchar_t to 16bit wchar_t

Update 2: The code which I have used can be found here

答:
The following is the code to convert UTF-32 encoded wide characters to UTF-16</p>

```<code>//Function to convert a Unicode string from platform-specific "wide characters" (wchar_t) to UTF-16.
void ConvertUTF32ToUTF16(wchar_t* source,
                         const uint32_t sourceLength,
                         wchar_t*& destination,
                         uint32_t& destinationLength)
{

  wchar_t wcharCharacter;
  uint32_t uniui32Counter = 0;

  wchar_t* pwszDestinationStart = destination;
  wchar_t* sourceStart = source;

  if(0 != destination)
  {
    while(uniui32Counter < sourceLength)
    {
      wcharCharacter = *source++;
      if(wcharCharacter <= 0x0000FFFF)
      {
        /* UTF-16 surrogate values are illegal in UTF-32
           0xFFFF or 0xFFFE are both reserved values */
        if(wcharCharacter >= 0xD800 &&
           wcharCharacter <= 0xDFFF)
        {
          *destination++ = 0x0000FFFD;
          destinationLength += 1;
        }
        else
        {
          /* source is a BMP Character */
          destinationLength += 1;
          *destination++ = wcharCharacter;
        }
      }
      else if(wcharCharacter > 0x0010FFFF)
      {
        /* U+10FFFF is the largest code point of Unicode Character Set */
        *destination++ = 0x0000FFFD;
        destinationLength += 1;
      }
      else
      {
        /* source is a character in range 0xFFFF - 0x10FFFF */
        wcharCharacter -= 0x0010000UL;
        *destination++ = (wchar_t)((wcharCharacter >> 10) + 0xD800);
        *destination++ = (wchar_t)((wcharCharacter & 0x3FFUL) + 0xDC00);
        destinationLength += 2;
      }

      ++uniui32Counter;
    }

    destination = pwszDestinationStart;
    destination[destinationLength] = '\0';
  }

  source = sourceStart;
} //function ends
</code>```

Body:
We have a C++ application deployed on RHEL using ICU.

We have a situation where in we need to convert UChar* to wchar_t* on linux. We use u_strToWCS to perform the conversion.

#include <iostream>
#include <wchar.h>

#include "unicode/ustring.h"

void convertUnicodeStringtoWideChar(const UChar* cuniszSource,
                                    const int32_t cunii32SourceLength,
                                    wchar_t*& rpwcharDestination,
                                    int32_t& destCapacity)
{
  UErrorCode uniUErrorCode = U_ZERO_ERROR;

  int32_t pDestLength = 0;

  rpwcharDestination     = 0;
  destCapacity = 0;

  u_strToWCS(rpwcharDestination,
             destCapacity,
             &pDestLength,
             cuniszSource,
             cunii32SourceLength,
             &uniUErrorCode);

  uniUErrorCode = U_ZERO_ERROR;
  rpwcharDestination = new wchar_t[pDestLength+1];
  if(rpwcharDestination)
  {
    destCapacity = pDestLength+1;

    u_strToWCS(rpwcharDestination,
               destCapacity,
               &pDestLength,
               cuniszSource,
               cunii32SourceLength,
               &uniUErrorCode);

    destCapacity = wcslen(rpwcharDestination);
  }
} //function ends

int main()
{
    //                     a       ä       Š       €    (          )
    UChar input[20] = { 0x0061, 0x00e4, 0x0160, 0x20ac, 0xd87e, 0xdd29, 0x0000 };
    wchar_t * output;
    int32_t outlen = 0;
    convertUnicodeStringtoWideChar( input, 6, output, outlen );
    for ( int i = 0; i < outlen; ++i )
    {
        std::cout << std::hex << output[i] << "\n";
    }
    return 0;
}

This works fine for characters entered upto 65535 (as UChar is implemented as uint16_t internally on linux). It fails to convert characters outside Basic Multilingual Plane (eg CJK Unified Ideographs Extension B)

Any ideas on how to perform the conversion?

Update 1: OK. I was looking at wrong directions. u_strToWCS works fine. The problem arises because I need to pass that wide string to a java application on windows using CORBA. Since wchar_t in linux is 32bit, I need to find a way to convert 32bit wchar_t to 16bit wchar_t

Update 2: The code which I have used can be found here

Body:
The following is the code to convert UTF-32 encoded wide characters to UTF-16

//Function to convert a Unicode string from platform-specific "wide characters" (wchar_t) to UTF-16.
void ConvertUTF32ToUTF16(wchar_t* source,
                         const uint32_t sourceLength,
                         wchar_t*& destination,
                         uint32_t& destinationLength)
{

  wchar_t wcharCharacter;
  uint32_t uniui32Counter = 0;

  wchar_t* pwszDestinationStart = destination;
  wchar_t* sourceStart = source;

  if(0 != destination)
  {
    while(uniui32Counter < sourceLength)
    {
      wcharCharacter = *source++;
      if(wcharCharacter <= 0x0000FFFF)
      {
        /* UTF-16 surrogate values are illegal in UTF-32
           0xFFFF or 0xFFFE are both reserved values */
        if(wcharCharacter >= 0xD800 &&
           wcharCharacter <= 0xDFFF)
        {
          *destination++ = 0x0000FFFD;
          destinationLength += 1;
        }
        else
        {
          /* source is a BMP Character */
          destinationLength += 1;
          *destination++ = wcharCharacter;
        }
      }
      else if(wcharCharacter > 0x0010FFFF)
      {
        /* U+10FFFF is the largest code point of Unicode Character Set */
        *destination++ = 0x0000FFFD;
        destinationLength += 1;
      }
      else
      {
        /* source is a character in range 0xFFFF - 0x10FFFF */
        wcharCharacter -= 0x0010000UL;
        *destination++ = (wchar_t)((wcharCharacter >> 10) + 0xD800);
        *destination++ = (wchar_t)((wcharCharacter & 0x3FFUL) + 0xDC00);
        destinationLength += 2;
      }

      ++uniui32Counter;
    }

    destination = pwszDestinationStart;
    destination[destinationLength] = '\0';
  }

  source = sourceStart;
} //function ends


问:
Casting objects from JSON array to custom classes in C#
I am using Visual Studio's auto generated REST Web Application project structure to create a RESTful API that consumes a JSON input.

Without going into too much detail, I have attempted to define a JSON structure like these:

Example 1:

```<code>"operation": {
    "type": "EXIST",
    "args": [
      {
        "ColumnName": "SomeColumnA",
        "Row": 2
      }
    ]
  }
</code>```

Example 2:

```<code>"operation": {
    "type": "ADD",
    "args": [
      {
        "type": "ADD",
        "args": [
          {
            "columnName": "SomeColumnB",
            "row": 12
          },
          {
            "columnName": "SomeColumnC",
            "row": 18
          }
        ]
      },
      20
    ]
  }
</code>```

operation represents one of any number of basic database operations and the arguments for those operations. In my first example, the operation is EXIST, which should check a database cell to see if a value exists or not. The args for this operation is simply an object that contains the column and row information for the cell to check (I call this a Value). In my second example, the function is ADD, which should add two values together and return the sum. Here, the arguments are a constant of 20 and a nested ADD function, which itself takes two Values. So, in general, the args array can take either primitive values, another nested operation, or a pair of values that represents a cell to read the actual value from. The ultimate goal here is to create a general structure that would allow me to nest combinations of functions, cell values, and constants to create compound functions like Average or Sum.

In my Models folder, I have the following classes to cast my data to:

```<code>public class Instruction
{
    public Operation[] Operations { get; set; }
}

public class Operation
{
    public string Type { get; set; }
    public object[] Args { get; set; }
}

public class Value
{
    public string ColumnName { get; set; }
    public int Row { get; set; }
}
</code>```

Note that the Args in Operation is of type object[].

When I call my web application by POSTing this JSON to it, C# automatically parses the JSON into objects defined in my Models folder. Say we used Example 1:

```<code>[HttpPost]
public IHttpActionResult Foo(Instruction instruction)
{
    foreach(Operation op in instruction.Operations) {
        switch (op.Type) {
            case "EXIST":
                Console.WriteLine("exist"); // works fine

                // since we got here, expect Args[0] to be type 'Value'
                var value = (Value) op.Args[0]; // InvalidCastException
                // logic for EXIST
            case "ADD":
                // logic for ADD
            // ...
        }
    }
}
</code>```

It's casting Operation just fine, and I get Type out correctly. I also get Args as an object[] with a lone element in it. But if I try to cast it to Value, it refuses to cast properly.

My question after all of this is: what is the best way to achieve what it looks like I'm attempting to do here? Am I on the right track? If so, what is my error? If I'm going about this the wrong way, what is a better practice alternative? Note that since I'm using Visual Studio's out-of-the-box Web Application framework I don't seem to have access to the function that deseralizes the JSON, so I don't think I can build a custom deserializer.

答:
See this fiddle that shows how I would use the dynamic type.

Fiddle

```<code>public static void Main()
{
    var json = @"{""operation"": {
        ""type"": ""ADD"",
        ""args"": [
            {
                ""type"": ""ADD"",
                ""args"": [
                    {
                        ""columnName"": ""SomeColumnB"",
                        ""row"": 12
                    },
                    {
                        ""columnName"": ""SomeColumnC"",
                        ""row"": 18
                    }
                ]
            }
        ]
    }}";
    dynamic data = JsonConvert.DeserializeObject(json);

    Console.WriteLine(data.operation.type.ToString());
    Console.WriteLine(data.operation.args[0].args[0].columnName.ToString());
    Console.WriteLine((int)data.operation.args[0].args[0].row);
}
</code>```

Body:
I am using Visual Studio's auto generated REST Web Application project structure to create a RESTful API that consumes a JSON input.

Without going into too much detail, I have attempted to define a JSON structure like these:

Example 1:

"operation": {
    "type": "EXIST",
    "args": [
      {
        "ColumnName": "SomeColumnA",
        "Row": 2
      }
    ]
  }

Example 2:

"operation": {
    "type": "ADD",
    "args": [
      {
        "type": "ADD",
        "args": [
          {
            "columnName": "SomeColumnB",
            "row": 12
          },
          {
            "columnName": "SomeColumnC",
            "row": 18
          }
        ]
      },
      20
    ]
  }

operation represents one of any number of basic database operations and the arguments for those operations. In my first example, the operation is EXIST, which should check a database cell to see if a value exists or not. The args for this operation is simply an object that contains the column and row information for the cell to check (I call this a Value). In my second example, the function is ADD, which should add two values together and return the sum. Here, the arguments are a constant of 20 and a nested ADD function, which itself takes two Values. So, in general, the args array can take either primitive values, another nested operation, or a pair of values that represents a cell to read the actual value from. The ultimate goal here is to create a general structure that would allow me to nest combinations of functions, cell values, and constants to create compound functions like Average or Sum.

In my Models folder, I have the following classes to cast my data to:

public class Instruction
{
    public Operation[] Operations { get; set; }
}

public class Operation
{
    public string Type { get; set; }
    public object[] Args { get; set; }
}

public class Value
{
    public string ColumnName { get; set; }
    public int Row { get; set; }
}

Note that the Args in Operation is of type object[].

When I call my web application by POSTing this JSON to it, C# automatically parses the JSON into objects defined in my Models folder. Say we used Example 1:

[HttpPost]
public IHttpActionResult Foo(Instruction instruction)
{
    foreach(Operation op in instruction.Operations) {
        switch (op.Type) {
            case "EXIST":
                Console.WriteLine("exist"); // works fine

                // since we got here, expect Args[0] to be type 'Value'
                var value = (Value) op.Args[0]; // InvalidCastException
                // logic for EXIST
            case "ADD":
                // logic for ADD
            // ...
        }
    }
}

It's casting Operation just fine, and I get Type out correctly. I also get Args as an object[] with a lone element in it. But if I try to cast it to Value, it refuses to cast properly.

My question after all of this is: what is the best way to achieve what it looks like I'm attempting to do here? Am I on the right track? If so, what is my error? If I'm going about this the wrong way, what is a better practice alternative? Note that since I'm using Visual Studio's out-of-the-box Web Application framework I don't seem to have access to the function that deseralizes the JSON, so I don't think I can build a custom deserializer.

Body:
See this fiddle that shows how I would use the dynamic type.

Fiddle

public static void Main()
{
    var json = @"{""operation"": {
        ""type"": ""ADD"",
        ""args"": [
            {
                ""type"": ""ADD"",
                ""args"": [
                    {
                        ""columnName"": ""SomeColumnB"",
                        ""row"": 12
                    },
                    {
                        ""columnName"": ""SomeColumnC"",
                        ""row"": 18
                    }
                ]
            }
        ]
    }}";
    dynamic data = JsonConvert.DeserializeObject(json);

    Console.WriteLine(data.operation.type.ToString());
    Console.WriteLine(data.operation.args[0].args[0].columnName.ToString());
    Console.WriteLine((int)data.operation.args[0].args[0].row);
}


问:
Pandas: Multiplying two columns of same dataframe thats dependent on third column
How can I multiply two columns of within a same dataframe? My dataframe looks like below image and I want to output like this. However, I cannot find how to multiply two columns that are dependent on first row of same dataframe. I would really appreciate some help on this.

```<code>request                            totalbytes
/login                              8520
/shuttle/countdown/                 7970
/shuttle/countdown/liftoff.html     0
</code>```

So far my output is below, but how can I get unique rows.

答:
Now that you explained what you want... You actually want to drop duplicates:</p>

```<code>(df['bytesbytes']*df['bytesfrequency']).drop_duplicates()
</code>```

Body:
How can I multiply two columns of within a same dataframe? My dataframe looks like below image and I want to output like this. However, I cannot find how to multiply two columns that are dependent on first row of same dataframe. I would really appreciate some help on this.

request                            totalbytes
/login                              8520
/shuttle/countdown/                 7970
/shuttle/countdown/liftoff.html     0

So far my output is below, but how can I get unique rows.

Body:
Now that you explained what you want... You actually want to drop duplicates:

(df['bytesbytes']*df['bytesfrequency']).drop_duplicates()


问:
Access ansible.cfg variable in task
How can I refer remote_tmp (or any other) value defined in ansible.cfg in my tasks? For example, in the my_task/defaults/main.yml:

```<code>file_ver: "1.5"
deb_file: "{{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb"
</code>```

produces an error:

```<code>fatal: [x.x.x.x]: FAILED! => {"failed": true,
    "msg": "the field 'args' has an invalid value,
            which appears to include a variable that is undefined.
            The error was: {{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb:
           'defaults' is undefined\... }
</code>```

答:
You can use lookup.

```<code>file_ver: "1.5"
deb_file: "{{ lookup('ini', 'remote_tmp section=defaults file=ansible.cfg' }}/deb_file_{{ file_ver }}.deb"
</code>```

EDIT

In case you don't know the path to the configuration file, you can set that to a fact by running the following tasks.

```<code>- name: look for ansible.cfg, see http://docs.ansible.com/ansible/intro_configuration.html
  local_action: stat path={{ item }}
  register: ansible_cfg_stat
  when: (item | length) and not (ansible_cfg_stat is defined and ansible_cfg_stat.stat.exists)
  with_items:
    - "{{ lookup('env', 'ANSIBLE_CONFIG') }}"
    - ansible.cfg
    - "{{ lookup('env', 'HOME') }}/.ansible.cfg"
    - /etc/ansible/ansible.cfg

- name: set fact for later use
  set_fact:
    ansible_cfg: "{{ item.item }}"
  when: item.stat is defined and item.stat.exists
  with_items: "{{ ansible_cfg_stat.results }}"
</code>```

You can then write:

```<code>file_ver: "1.5"
deb_file: "{{ lookup('ini', 'remote_tmp section=defaults file=' + ansible_cfg) }}/deb_file_{{ file_ver }}.deb"
</code>```

Title: Access ansible.cfg variable in task

Body:
How can I refer remote_tmp (or any other) value defined in ansible.cfg in my tasks? For example, in the my_task/defaults/main.yml:

file_ver: "1.5"
deb_file: "{{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb"

produces an error:

fatal: [x.x.x.x]: FAILED! => {"failed": true,
    "msg": "the field 'args' has an invalid value,
            which appears to include a variable that is undefined.
            The error was: {{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb:
           'defaults' is undefined\... }

Body:
You can use lookup.

file_ver: "1.5"
deb_file: "{{ lookup('ini', 'remote_tmp section=defaults file=ansible.cfg' }}/deb_file_{{ file_ver }}.deb"

EDIT

In case you don't know the path to the configuration file, you can set that to a fact by running the following tasks.

- name: look for ansible.cfg, see http://docs.ansible.com/ansible/intro_configuration.html
  local_action: stat path={{ item }}
  register: ansible_cfg_stat
  when: (item | length) and not (ansible_cfg_stat is defined and ansible_cfg_stat.stat.exists)
  with_items:
    - "{{ lookup('env', 'ANSIBLE_CONFIG') }}"
    - ansible.cfg
    - "{{ lookup('env', 'HOME') }}/.ansible.cfg"
    - /etc/ansible/ansible.cfg

- name: set fact for later use
  set_fact:
    ansible_cfg: "{{ item.item }}"
  when: item.stat is defined and item.stat.exists
  with_items: "{{ ansible_cfg_stat.results }}"

You can then write:

file_ver: "1.5"
deb_file: "{{ lookup('ini', 'remote_tmp section=defaults file=' + ansible_cfg) }}/deb_file_{{ file_ver }}.deb"