Frage

Ich bin versucht, ein zu schaffen Toast Pop-up, wenn das Symbol am unteren Rande des Layouts (das Bildschirm-Symbol) http://i.stack.imgur.com/C8WgN.png

Ich möchte die Informationen eingegeben wie eine Lieferadresse setzen in den Toast Benachrichtigung werden

Zuerst Last

Straße

City State Zip

gibt es eine Möglichkeit, dies wo der Toast fordert die IDs für die EditText Ansichten zu tun?

Die .xml mit dem Layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:stretchColumns="2" android:orientation="vertical">
 <TableRow>
     <TextView
         android:text="First Name"
         android:padding="3dip" android:layout_column="0"/>
     <TextView
         android:text="Last Name" android:padding="3dip"/>

 </TableRow>
 <TableRow>
   <EditText 
            android:layout_height="wrap_content" 
            android:id="@+id/EditText01" 
            android:inputType="textPersonName"      
            android:width="150dip"/>
  <EditText android:singleLine="true" 
            android:inputType="textPersonName" 
            android:isScrollContainer="false" 
            android:layout_height="wrap_content" 
            android:id="@+id/EditText02" 
            android:lines="1" android:width="150dip"></EditText>
  </TableRow>
  <View
     android:background="#FF909090" android:layout_height="2px"/>
  <TableRow>
     <TextView
         android:text="Street Address"
         android:padding="3dip" android:layout_column="0"/>
  </TableRow>

  <TableLayout>
    <TableRow android:layout_width="fill_parent">
    <TextView 
              android:text="Line 1"
               android:padding="3dip" 
                            android:layout_column="0"/>
    <EditText
    android:layout_height="wrap_content"
    android:id="@+id/EditText03" 
                            android:inputType="textPostalAddress" 
                            android:width="255dip"/>
   </TableRow>
   <TableRow android:layout_width="fill_parent">
      <TextView 
    android:text="Line 2"
    android:padding="3dip" android:layout_column="0"/>
   <EditText
    android:layout_height="wrap_content"
    android:id="@+id/EditText04" 
                            android:inputType="textPostalAddress"/>
  </TableRow>
</TableLayout>

<TableLayout>
<TableRow>
<TextView
 android:text="City"
 android:padding="3dip" 
 android:layout_column="0" />
<EditText 
 android:layout_height="wrap_content"
 android:id="@+id/EditText05" 
 android:inputType="text" 
 android:layout_width="120px"/>
</TableRow>
<TableLayout>
  <TableRow>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:text="@string/state" />
    <Spinner 
        android:layout_height="wrap_content"
        android:prompt="@string/state"
        android:id="@+id/Spinner01" 
        android:layout_width="wrap_content"/>
    <TextView
     android:layout_height="wrap_content"
     android:text="Zipcode" />
    <EditText 
     android:layout_height="wrap_content" 
     android:inputType="phone" android:width="80px"/>
</TableRow>
</TableLayout>
</TableLayout>
<View
     android:background="#FF909090" android:layout_height="2px"/>
 <TableRow>
  <TextView
   android:layout_width="120px"
   android:layout_height="wrap_content"
   android:text="Telephone Number" 
   android:padding="3dip"/>
 </TableRow>
 <TableLayout>
  <TableRow>
   <EditText
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:layout_width="120dip" />
  <Button android:id="@+id/Button01"   
          android:layout_width="wrap_content"   
          android:layout_height="wrap_content" 
          android:padding="3dip" 
          android:background="@drawable/ic_monitor_grey"         
          android:clickable="true" />
  </TableRow>
  </TableLayout>
  </TableLayout>
  </ScrollView>

Mit meiner .java-Datei zu sein

public class Basic extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic);
    Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.state_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

   }
}
War es hilfreich?

Lösung

You would need to do a few things.

  1. For each editText area you want to get the values from, you'll want to define an android:id using the following style of syntax

  2. Retrieve the views you'd like to use from your xml layout inside the Java. Based on the above, you'd want to add something to you onCreate like:

    EditText phoneField = (EditText) findViewById(R.id.phone_field)

  3. Retrieve the value from the EditText object

    String phoneNumber = phoneField.getText().toString()

  4. Show the field in a Toast message Toast toDisplay = Toast.makeText(context, phoneNumber) toDisplay.show()

There are obviously tons of additional things you could do, but that would be about the minimum.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top