Vorlesungen
  Download     DBS     Sprachen     Oberflächen     File Formats     Impressum     Datenschutz  
1. Sem
2. Sem
3. Sem
4. Sem
Android
Mobile Applikationen und Infrastrukturen
5. Sem
Wahlpflicht-SoSe
Wahlpflicht-WiSe
Projektwochen
Allgemein:
Startseite
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien

BottomNavigationAdd

navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/navigation_add"

android:icon="@drawable/ic_add_24dp"
android:title="@string/title_add" />

<item
android:id="@+id/navigation_sub"
android:icon="@drawable/ic_sub_24dp"
android:title="@string/title_sub" />

<item
android:id="@+id/navigation_mult"
android:icon="@drawable/ic_mult_24dp"
android:title="@string/title_mult" />
<item
android:id="@+id/navigation_div"
android:icon="@drawable/ic_div_24dp"
android:title="@string/title_div" />
<item
android:id="@+id/navigation_sqr"
android:icon="@drawable/ic_sqr_24dp"
android:title="@string/title_sqr" />

</menu>

Fragment_add.java

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import java.util.Random;public class AddFragment extends Fragment {

private TextView edNumber1 = null;
private TextView edNumber2 = null;
private EditText edNumber3 = null;
private EditText edComment = null;

private Button bnTesten=null;
private Button bnAgain=null;
private int zahl1=0;
private int zahl2=0;
private int ergebnis=0;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle saveInstanceState ) {
View view = inflater.inflate(R.layout. fragment_add , container, false);
edNumber1 = (TextView) view.findViewById(R.id. ednumber1 );
edNumber2 = (TextView) view.findViewById(R.id. ednumber2 );
edNumber3 = (EditText) view.findViewById(R.id. ednumber3 );
edComment = (EditText) view.findViewById(R.id. edcomment );

edNumber1.setText("12");

bnTesten = (Button) view.findViewById(R.id. bntesten );
bnAgain = (Button) view.findViewById(R.id. bnagain );
bnTesten.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
bnTest_click();
}
}
);
bnAgain.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
bnAgain_click();
}
}
);

setRandomNumbers();
return view;
} // onCreate

private void setRandomNumbers() {
Random rand = new Random();
this.zahl1 = rand.nextInt(500)+1;
this.zahl2 = rand.nextInt(500)+1;
this.ergebnis = this.zahl1+this.zahl2;
this.edNumber1.setText(Integer.toString(this.zahl1));
this.edNumber2.setText(Integer.toString(this.zahl2));
this.edNumber3.setText("");
this.edComment.setText("");
Log.e("Zahl1",Integer.toString(this.zahl1));
Log.e("Zahl2",Integer.toString(this.zahl2));
}

// Rückgabe a) Eingabe okay b) eingegebene Zahl
private Object[] getIntNumber(EditText edText) {
Object[] objects = new Object[2];
try {
String s = edText.getText().toString();
int zahl = Integer.parseInt(s);
objects[0] = true;
objects[1] = zahl;
}
catch (NumberFormatException e) {
objects[0] = false;
objects[1] = -1;
}
return objects;
}

private void bnTest_click(){
Object[] values;
values = getIntNumber(edNumber3);
if (! ((Boolean)values[0]) ) {
edComment.setText(getString(R.string. wrongnumberformat ));
return;
}
int ergebnis = ((Integer)values[1]).intValue();
if (ergebnis==this.ergebnis) {
edComment.setText(getString(R.string. correctnumber ));
}
else {
edComment.setText(getString(R.string. wrongnumber ));
}
} // bnTest_click

private void bnAgain_click() {
setRandomNumbers();
}

}

fragment_add.xml

<? xml version= "1.0" encoding= "utf-8" ?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
xmlns: tools = "http://schemas.android.com/tools"
android :id= "@+id/activity_main"
android :layout_width= "match_parent"
android :layout_height= "match_parent"
android :paddingBottom= "@dimen/activity_vertical_margin"
android :paddingLeft= "@dimen/activity_horizontal_margin"
android :paddingRight= "@dimen/activity_horizontal_margin"
android :paddingTop= "@dimen/activity_vertical_margin"
>

<TextView
android :id= "@+id/maintitle"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
android :textSize= "20dp"
android :text= "@string/caption_add"
android :textColor= "@color/colorAccent"
android :layout_margin= "4dp"
/>
<TextView
android :id= "@+id/tvnumber1"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_marginLeft= "20dp"
android :width= "170dp"
android :textSize= "16dp"
android :text= "@string/number1"
android :layout_below= "@id/maintitle"
/>

<TextView
android :id= "@+id/ednumber1"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_alignBaseline= "@id/tvnumber1"
android :layout_toRightOf= "@id/tvnumber1"
android :text= "10.0"
android :width= "100dp"
android :background= "@color/colorNumbersBackground"
android :textColor= "@color/colorNumbersForeground"
android :textSize= "16dp" /> <TextView
android :id= "@+id/symbol"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"

android :textColor= "@color/colorSymbol"
android :textSize= "20dp"
android :text= "+"
android :layout_centerHorizontal= "true"
android :layout_below= "@id/tvnumber1"
/>

<TextView
android :id= "@+id/tvnumber2"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_marginLeft= "20dp"
android :width= "170dp"
android :textSize= "16dp"
android :text= "@string/number2"
android :layout_below= "@id/symbol"
/>
<TextView
android :id= "@+id/ednumber2"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :textSize= "16dp"
android :text= "7"
android :width= "100dp"
android :background= "@color/colorNumbersBackground"
android :textColor= "@color/colorNumbersForeground"

android :layout_toRightOf= "@id/tvnumber2"
android :layout_alignBaseline= "@id/tvnumber2"
/>
<TextView
android :id= "@+id/symbol2"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_marginTop= "30dp"
android :textColor= "@color/colorSymbol"
android :textSize= "20dp"
android :text= "="

android :layout_centerHorizontal= "true"
android :layout_below= "@id/tvnumber2"
/>

<TextView
android :id= "@+id/tvnumber3"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_marginLeft= "20dp"
android :width= "170dp"
android :textSize= "16dp"
android :text= "@string/result"
android :layout_below= "@id/symbol2"
/>
<EditText
android :id= "@+id/ednumber3"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :textSize= "16dp"
android :text= "7"
android :width= "100dp"
android :inputType= "number"
android :background= "@color/colorNumbersBackground"
android :textColor= "@color/colorNumbersForeground"
android :layout_toRightOf= "@id/tvnumber3"
android :layout_alignBaseline= "@id/tvnumber3"
/>


<Button
android :id= "@+id/bntesten"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :text= "@string/bntest"
android :layout_marginTop= "40dp"
android :layout_marginLeft= "20dp"
android :layout_below= "@id/tvnumber3"

/>

<Button
android :id= "@+id/bnagain"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :text= "@string/bnagain"
android :layout_toRightOf= "@id/bntesten"
android :layout_alignBaseline= "@id/bntesten"
/>

<!-- ******************** -->
<TextView
android :id= "@+id/tvcomment"
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :layout_marginLeft= "20dp"
android :width= "170dp"
android :textSize= "16dp"
android :text= "@string/result"
android :layout_below= "@id/bntesten"
/>
<EditText
android :id= "@+id/edcomment"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
android :textSize= "16dp"
android :text= "xxxxxxxxxxx"
android :layout_marginTop= "-15dp"
android :layout_below= "@id/tvcomment"
android :layout_marginLeft= "20dp"
/>
</RelativeLayout>


Button
CheckBox