P
Panguan
Neues Mitglied
- 1
Hi,
seit heute versuche ich Androidapps zu programmieren und hab gleich ein paar Fragen bzw. Probleme. Hab auch schon ein Tutorial gemacht
Mein Programm soll im groben ein 3x3 Feld besitzen(vermutlich aus Buttons).
Wie kann ich prüfen, ob mehrere dieser Buttons gleichzeitig gedrückt werden?
Geht das überhaupt? Wenn ja wird dabei zufälligerweise Multithreading benötigt?
Und zweitens: Sollte man "normale" Buttons dafür benutzen oder eher mithilfe von Canvas welche zeichnen lassen?(Geht auch um den Aspekt der Effizienz)
Danke für eure Antworten, ich bin wie gesagt noch etwas neu in dem Gebiet
Panguan
Edit:
Ich hab mich jetzt für die Buttons entschieden, jedoch weiß ich nicht wie ich den aktuell gedrückten abfragen kann.
.Java
.Xml:
Optisch soll das ungefähr so aussehen:
http://www.directupload.net/file/d/3522/xke339d9_jpg.htm
seit heute versuche ich Androidapps zu programmieren und hab gleich ein paar Fragen bzw. Probleme. Hab auch schon ein Tutorial gemacht
Mein Programm soll im groben ein 3x3 Feld besitzen(vermutlich aus Buttons).
Wie kann ich prüfen, ob mehrere dieser Buttons gleichzeitig gedrückt werden?
Geht das überhaupt? Wenn ja wird dabei zufälligerweise Multithreading benötigt?
Und zweitens: Sollte man "normale" Buttons dafür benutzen oder eher mithilfe von Canvas welche zeichnen lassen?(Geht auch um den Aspekt der Effizienz)
Danke für eure Antworten, ich bin wie gesagt noch etwas neu in dem Gebiet
Panguan
Edit:
Ich hab mich jetzt für die Buttons entschieden, jedoch weiß ich nicht wie ich den aktuell gedrückten abfragen kann.
.Java
Code:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
int counter = 0;
public View btn1;
public View btn2;
public View btn3;
public View btn4;
public View btn5;
public View btn6;
public View btn7;
public View btn8;
public View btn9;
public TextView tw;
public TextView tw2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
btn1 = findViewById(R.id.button1);
btn1.setOnClickListener(this);
btn2 = findViewById(R.id.button2);
btn2.setOnClickListener(this);
btn3 = findViewById(R.id.button3);
btn3.setOnClickListener(this);
btn4 = findViewById(R.id.button4);
btn4.setOnClickListener(this);
btn5 = findViewById(R.id.button5);
btn5.setOnClickListener(this);
btn6 = findViewById(R.id.button6);
btn6.setOnClickListener(this);
btn7 = findViewById(R.id.button7);
btn7.setOnClickListener(this);
btn8 = findViewById(R.id.button8);
btn8.setOnClickListener(this);
btn9 = findViewById(R.id.button9);
btn9.setOnClickListener(this);
tw = (TextView)findViewById(R.id.textView1);
tw2 = (TextView)findViewById(R.id.textView2);
return true;
}
public void onClick(View v) {
counter = counter + 1;
tw.setText("Du hast geklickt! " + counter);
tw2.setText(v.getId());
}
}
Code:
<RelativeLayout 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:focusable="true"
android:gravity="start|fill"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button7"
android:layout_alignLeft="@+id/button5"
android:layout_toLeftOf="@+id/button9"
android:minHeight="100dip"
android:text="Button8" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button8"
android:layout_alignBottom="@+id/button8"
android:layout_alignLeft="@+id/button6"
android:minHeight="100dip"
android:minWidth="100dp"
android:text="Button9" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignTop="@+id/button5"
android:layout_toLeftOf="@+id/button5"
android:minHeight="100dip"
android:minWidth="100dp"
android:text="Button4" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button6"
android:layout_alignLeft="@+id/button6"
android:layout_alignParentRight="true"
android:minHeight="100dip"
android:text="Button3" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="TextView1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/button2"
android:minHeight="100dip"
android:minWidth="100dip"
android:text="Button5" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/button2"
android:layout_toRightOf="@+id/button5"
android:minHeight="100dip"
android:text="Button6" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button4"
android:minHeight="100dip"
android:minWidth="100dip"
android:text="Button2" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="19dp"
android:layout_toLeftOf="@+id/button5"
android:minHeight="100dip"
android:minWidth="100dip"
android:text="Button1" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_toLeftOf="@+id/button8"
android:minHeight="100dip"
android:minWidth="100dip"
android:text="Button7" />
</RelativeLayout>
http://www.directupload.net/file/d/3522/xke339d9_jpg.htm
Zuletzt bearbeitet: