Java Reference
In-Depth Information
Listing 16.1 Klasse Activity1 mit ausprogrammiertem Aufbau der Oberfl ├Ąche
package javacomp.android.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Activity1 extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv1 = new TextView(this);
tv1.setText("Eingabe:");
EditText editText = new EditText(this);
Button b = new Button(this);
b.setText("Absenden");
TextView tv2 = new TextView(this);
Listener l = new Listener(editText, tv2);
b.setOnClickListener(l);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv1);
ll.addView(editText);
ll.addView(b);
ll.addView(tv2);
setContentView(ll);
}
}
class Listener implements View.OnClickListener
{
private EditText editText;
private TextView tv;
public Listener(EditText editText, TextView tv)
{
this.editText = editText;
this.tv = tv;
}
public void onClick(View v)
{
String input = editText.getText().toString();
tv.setText(input);
}
}
 
Search WWH ::




Custom Search