Login Formular

N

Naxtrumrar

Neues Mitglied
0
Hallo Leute, bin ganz neu in der Android Entwicklung, arbeite aber schon seit über einem Jahr mit Java.

Ich versuch mich grad daran ein Dialog beim Start aufploppen zu lassen, wo man eine IP Adresse und ein Passwort angeben soll. Und da haperts bei mir wie man das XML Layout erstellt und wie mans korrekt im Programm implementiert, denn eine Haupt GUI habe ich ja schon. Das soll sozusagen so funktionieren, wie wenn ich in Java ein JPanel habe was die eigentliche Oberfläche ist und dann aber ein JDialog sich öffnen soll mit 2 Texteingabe und ein Button.

Danke
 
Danke aber genau das habe ich shcon ausprobiert, und mein Problem dabei ist, dass immer nur ein Eingabefeld da dann angezeigt wird....
 
dann solltest du uns wohl ein bisschen vom deinem code zeigen, damit wir dir helfen können.
 
Seitdem ich das eingefügt habe stürzt das Programm ganz ab:

Code:
Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);

        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Custom Dialog");

        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Hello, this is a custom dialog!");

        setContentView(R.layout.custom_dialog);

custom_dialog.xml
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>
 
Eclipse => logcat hilft immer
 
Ok war eine Nullpointer Exception - die Exception wurde behoben jetzt stürzt das Programm nichtmehr ab, allerdings zeigt es jetzt gar nichts an.

Hier mal der komplette Code:

PCRemoteSteuern.java
PHP:
(imports diesdas..)

public class PCRemoteSteuern extends Activity
{
    //Objekte werden gesetzt
    public final String ipAdresse = "192.168.3.100";
    public final int port = 1030;
    public TextView label_ausgabe;
    

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        //GUI aus XML erzeugen
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      //Funktionen definieren
        Button b_killwinamp = (Button)this.findViewById(R.id.b_killwinamp);
            b_killwinamp.setOnClickListener(new OnClickListener()
                {
                    public void onClick(View v)
                    {
                        sende("Start1$Winamp$Kill");
                    }
                });
        Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);

        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Custom Dialog");

        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Hello, this is a custom dialog!");

        setContentView(R.layout.custom_dialog);
        
    }
    /** create the login form */
    private void sende(String text)
    {
        Socket socket = null;
        BufferedWriter buffout = null;
        try
        {
            socket = new Socket( ipAdresse, port );
            buffout = new BufferedWriter( new OutputStreamWriter( socket.getOutputStream() ) );
            buffout.write( text );
            buffout.newLine();
            buffout.flush();
            buffout.close();
            socket.close();
        }catch(UnknownHostException e){e.printStackTrace();}
        catch(IOException e){e.printStackTrace();}
    }
}

die main.xml:

HTML:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
    android:id="@+id/widget184"
    android:layout_width="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/ueberschrift"
        android:layout_width="197px"
        android:layout_height="24px"
        android:text="Programm remoteMyPC"
        android:textSize="16sp"
        android:textStyle="bold"
        android:layout_x="0px"
        android:layout_y="0px"
    >
    </TextView>
    <TableRow 
        android:layout_width="fill_parent" 
        android:id="@+id/widget226" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal">
    <TableRow 
        android:layout_width="fill_parent" 
        android:layout_height="26px" 
        android:id="@+id/widget220" 
        android:orientation="horizontal">
    </TableRow>
    </TableRow>
    <TextView 
        android:layout_width="wrap_content" 
        android:textSize="16px" 
        android:id="@+id/l_kill" 
        android:layout_height="wrap_content" 
        android:text="Programm Killen:" 
        android:layout_x="5dip" 
        android:layout_y="24dip">
    </TextView>
    <TextView 
        android:layout_width="139px" 
        android:textSize="16sp" 
        android:id="@+id/l_starten" 
        android:layout_height="wrap_content" 
        android:text="Programm Starten:" 
        android:layout_x="4dip" 
        android:layout_y="157dip">
    </TextView>
    <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/b_killqip" 
        android:text="QIP" 
        android:layout_x="76dip" 
        android:layout_y="52dip"></Button>
    <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/b_killfirefox" 
        android:text="Firefox" 
        android:layout_x="-5dip" 
        android:layout_y="53dip" 
        android:layout_width="wrap_content">
    </Button>
    
    <Button
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/b_killwinamp" 
        android:text="Winamp" 
        android:layout_x="132dip" 
        android:layout_y="52dip">
    </Button>
    <Button 
        android:id="@+id/b_killiexplorer" 
        android:layout_width="87px" 
        android:text="I-Explorer" 
        android:layout_height="wrap_content" 
        android:layout_x="217dip" 
        android:layout_y="52dip">
    </Button>
</AbsoluteLayout>

Und wie oben im Beitrag unverändert die custom_dialog.xml
 
Ist jetzt nicht überraschend, dass du nichts angezeigt kriegst:
Erst setzt du das Layout deiner aktuellen Activity per
Code:
setContentView(R.layout.main);
Erstellst dann deinen Dialog (sieht soweit gut aus)
und überschreibst anschließend das Layout von der Activity mit
Code:
setContentView(R.layout.custom_dialog);
Jedoch hast du die Werte vom TextView vorher nur in dem neuen Dialog gesetzt - dieser Dialog wird jedoch nie angezeigt.
Ergo: die letzte Zeile setContentView rausschmeißen - und an irgendeiner stelle deinen Dialog per dialog.show() mal anzeigen!
 
Okay danke, das hat mich schonmal gut weitergebracht, jetzt sehe ich den Fehler natürlich auch. Liegt am ganzen hin und her kopieren von den Codeschnipseln ^^ Werde ich dann heute Nachmittag zu Hause mal ausprobieren.
 
Habe leider erst jetzt wieder Zeit hierfür gefunden. Aber das Problem besteht immernoch, habe jetzt

setContentView(R.layout.custom_dialog);

rausgeschmissen und einfach am ende dialog.show() eingebaut, jetzt stürzt die Anwendung aber sofort beim Starten ab...
 
Ich glaube der passende Logcat-eintrag , hilft uns mehr dir zu helfen :D
ein "geht nich :(" hilft meistens recht wenig ^.^

MfG nijoX
 

Ähnliche Themen

Manny87
  • Manny87
Antworten
11
Aufrufe
166
swa00
swa00
F
Antworten
0
Aufrufe
837
FlorianAlfredo
F
J
Antworten
0
Aufrufe
557
JoEntwickler
J
Zurück
Oben Unten