Horizontal Swipe in an activity

72 views Asked by At

Im trying to use horizontal paging for my calculation results, which only differ by a few numbers. so it's easy to overview the results. The problem is that these result pages are extended by ActionBarActivity so its not possible for me to extend them by Fragment. Thanks in advance!

Here's my code for the first fragment:

package com.example.j_ricke.livestocknutritioncalc;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


public class displaynutrition extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_displaynutrition);
        Intent intent = getIntent();
        double amount = intent.getDoubleExtra("Amount", 0);
        double MJ = intent.getDoubleExtra("MJ", 0);
        double MJpro100 = (MJ/amount)*100;

        double MJround = Math.round(MJ);

        String MJstring = String.valueOf(MJround);
        String amountstring = String.valueOf(amount);
        String MJpro100string = String.valueOf(MJpro100);


        TextView totalweightsheep = (TextView) findViewById(R.id.totalweightsheep);
        TextView nutritionvaluesheep = (TextView) findViewById(R.id.nutritionvaluesheep);
        TextView totalnutritionvaluesheep = (TextView) findViewById(R.id.totalnutritionvaluesheep);

        nutritionvaluesheep.setText(MJpro100string+"MJ");
        totalweightsheep.setText(amountstring+"g");
        totalnutritionvaluesheep.setText(MJstring+"MJ");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_displaynutrition, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void endnutrition(View view)
    {
        finish();
        EditText editText1 = (EditText) findViewById(R.id.amount1);
        EditText editText2 = (EditText) findViewById(R.id.amount2);
        EditText editText3 = (EditText) findViewById(R.id.amount3);
        EditText editText4 = (EditText) findViewById(R.id.amount4);
        EditText editText5 = (EditText) findViewById(R.id.amount5);
        EditText editText6 = (EditText) findViewById(R.id.amount6);
        editText1.setText("");
        editText2.setText("");
        editText3.setText("");
        editText4.setText("");
        editText5.setText("");
        editText6.setText("");
    }
    public void changenutrition(View view)
    {
        finish();
    }

}

The other pages would look the same but with different results. XML for the UI:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.j_ricke.livestocknutritioncalc.displaynutrition"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView android:text="@string/naehrwert"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="22sp"
            android:fontFamily="Arial"
            android:textColor="#000000" />
        <TextView android:text="@string/menge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="22sp"
            android:fontFamily="Arial"
            android:layout_marginLeft="170dp"
            android:textColor="#000000" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1"
        android:layout_marginTop="10dp">
        <TextView
            android:layout_width="185dp"
            android:layout_height="wrap_content"
            android:id="@+id/nutritionvaluesheep"
            android:layout_weight="0.38">
        </TextView>
        <TextView
            android:layout_width="79dp"
            android:layout_height="wrap_content"
            android:text="@string/gramm100"
            android:layout_marginLeft="65dp"
            android:textSize="18sp"
            android:textColor="#000000"
            android:enabled="false" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/total"
            android:textStyle="bold"
            android:textSize="18sp"
            android:textColor="#000000" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">
        <TextView
            android:layout_width="185dp"
            android:layout_height="wrap_content"
            android:id="@+id/totalnutritionvaluesheep"
            android:layout_weight="0.38">
        </TextView>
        <TextView
            android:layout_width="79dp"
            android:layout_height="wrap_content"
            android:id="@+id/totalweightsheep"
            android:layout_marginLeft="65dp"
            android:textSize="16sp"
            android:textColor="#000000" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1"
        android:layout_marginTop="50dp">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/change"
            android:text="@string/ende"
            android:layout_weight="0.38"
            android:textColor="#000000"
            android:layout_marginLeft="50dp"
            android:textSize="16sp"
            android:onClick="endnutrition">
        </Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/end"
            android:text="@string/aendern"
            android:textSize="16sp"
            android:textColor="#000000"
            android:layout_marginLeft="25dp"
            android:onClick="changenutrition"/>
    </LinearLayout>

</LinearLayout>
0

There are 0 answers