2017-05-22 3 views
-3

Ich habe meine Haare für die letzten 4 Stunden wurde ziehen versucht, herauszufinden, wie dies zu tun.Anfahrt Wert von ** ** Bearbeiten von Text und in einem Textview Anzeige in einer anderen Aktivität

Ich habe SO für andere Fragen überprüft, aber nichts gutes gefunden. Ich bin ein Zwischen Programmierer und wäre sehr dankbar, wenn Sie Ihre Kommentare und Antworten in einer Art und Weise geschrieben, die ich verstehen kann.

Ich mag den Text zu übernehmen können, die der Benutzer in denen auf der InputPage Aktivität @+id/location EditText Feld betritt und zeigt sie in der @+id/ListName Textview auf der InputPage2 Aktivität, wenn die Taste auf der InputPage Aktivität gedrückt wird.

InputPage Java-Code

public class InputPage extends Activity { 
    public String name; 
    public InputPage() { 
} 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_input_page); 
     Button button = (Button)findViewById(R.id.addButton); 
    } 


    public InputPage(String name) { 
     this.name = name; 
    } 

    public String getName() { 
     return name; 
    } 
    public String name(String name){ 
     this.name = name; 
     EditText editText = (EditText)findViewById(R.id.location); 
     String value = editText.getText().toString(); 
     return value; 

    } 

    public void toInputScreen2(View view) { 
     Button button = (Button) findViewById(R.id.button2); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent2 = new Intent(InputPage.this, InputPage2.class); 
       startActivity(intent2); 
      } 
     }); 
    } 
} 

XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".InputPage" 
    android:background="@color/BackgroundGrey"> 

    <TextView 
     android:id="@+id/mapNo" 
     android:layout_width="wrap_content" 
     android:layout_height="35dp" 
     android:text="@string/mapNoTextBox" 
     android:textColor="@color/textColour" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="16dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintHorizontal_bias="0.04" 
     app:layout_constraintVertical_bias="0.13" /> 

    <TextView 
     android:id="@+id/inputPageTitle" 
     android:layout_width="178dp" 
     android:layout_height="21dp" 
     android:text="@string/inputPageTitle" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:textColor="@color/textColour" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintVertical_bias="0.01999998" /> 

    <EditText 
     android:id="@+id/noInput" 
     android:layout_width="48dp" 
     android:layout_height="39dp" 
     android:ems="10" 
     android:inputType="number" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintVertical_bias="0.13" 
     app:layout_constraintHorizontal_bias="0.51" /> 

    <TextView 
     android:layout_width="150dp" 
     android:layout_height="38dp" 
     android:text="@string/location" 
     android:textColor="@color/textColour" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintHorizontal_bias="0.041" 
     app:layout_constraintVertical_bias="0.24" /> 

    <EditText 
     android:id="@+id/location" 
     android:layout_width="177dp" 
     android:layout_height="44dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:hint="@string/hintText" 
     android:textColorHint="@color/hintTextColour" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintHorizontal_bias="0.952" 
     app:layout_constraintVertical_bias="0.243" /> 

    <EditText 
     android:id="@+id/dateBox" 
     android:layout_width="133dp" 
     android:layout_height="44dp" 
     android:ems="10" 
     android:inputType="date" 
     android:hint="@string/dateBoxHint" 
     android:textColorHint="@color/hintTextColour" 
     android:layout_marginLeft="61dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintHorizontal_bias="0.335" 
     app:layout_constraintVertical_bias="0.374" /> 

    <TextView 
     android:layout_width="101dp" 
     android:layout_height="34dp" 
     android:text="@string/dateBox" 
     android:textColor="@color/textColour" 
     android:textStyle="bold" 
     android:textSize="30sp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintHorizontal_bias="0.032" 
     app:layout_constraintVertical_bias="0.369" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="165dp" 
     android:layout_height="58dp" 
     android:text="@string/continueButton" 
     android:background="@drawable/buttons" 
     android:layout_marginRight="8dp" 
     android:onClick="toInputScreen2" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintHorizontal_bias="0.502" 
     app:layout_constraintVertical_bias="0.778" /> 


</android.support.constraint.ConstraintLayout> 

** InputPage2 Code java **

public class InputPage2 extends Activity { 

    Button saveButton1; 
    EditText message; 
    String Message; 
    TextView[] pairs; 
    int num_match; 




    public TextView[] getPairs() { 
     return pairs; 
    } 

    public void setPairs(TextView[] pairs) { 
     this.pairs = pairs; 
    } 

    public int getNum_match() { 
     return num_match; 
    } 

    public void setNum_match(int num_match) { 
     this.num_match = num_match; 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_input_page2); 
     message = (EditText) findViewById(R.id.textNotAtHomes); 



    } 

    public void toSaveField(View v) { 
     saveButton1 = (Button) findViewById(R.id.saveButton1); 
     saveButton1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      } 

     }); 


     Message = message.getText().toString(); 
     try { 
      FileOutputStream fos = openFileOutput("Text.txt", MODE_WORLD_READABLE); 
      OutputStreamWriter osw = new OutputStreamWriter(fos); 
      try { 
       osw.write(Message); 
       osw.flush(); 
       osw.close(); 
       Toast.makeText(getBaseContext(), "Saved successfully", Toast.LENGTH_LONG).show(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } 

     Intent intent2 = new Intent(InputPage2.this, MainActivity.class); 
     startActivity(intent2); 
    } 

    public void linearLayout(TextView[] pairs, int num_match) { 
     LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout); 
     LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 
       ViewGroup.LayoutParams.WRAP_CONTENT); 
     pairs = new TextView[num_match + 1]; 
     for (int l = 1; l <= num_match; l++) { 
      pairs[1].setTextSize(15); 
      pairs[1].setLayoutParams(layoutParams); 
      pairs[1].setId(l); 
      linearLayout.addView(pairs[1]); 

     } 
    } 
} 

zugehörigen XML-

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".InputPage2" 
    android:background="#ffffff" 
    tools:layout_editor_absoluteY="25dp" 
    tools:layout_editor_absoluteX="0dp" 
    android:backgroundTint="@color/BackgroundGrey"> 


    <Button 
     android:onClick="toSaveField" 
     android:id="@+id/saveButton1" 
     android:layout_width="341dp" 
     android:layout_height="70dp" 
     android:background="@drawable/buttons" 
     android:text="@string/saveButton" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintHorizontal_bias="0.666" 
     app:layout_constraintVertical_bias="1.0" 
     android:layout_marginStart="8dp" 
     android:layout_marginEnd="8dp" /> 


    <EditText 
     android:id="@+id/textNotAtHomes" 
     android:layout_width="346dp" 
     android:layout_height="477dp" 
     android:ems="10" 
     android:background="@color/hintTextColour" 
     android:inputType="textMultiLine" 
     android:hint="@string/hintText2" 
     android:textColorHint="@color/hintTextColour2" 
     android:layout_marginLeft="8dp" 
     android:gravity="fill_horizontal" 
     android:padding="6dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintVertical_bias="0.303" /> 

    <TextView 
     android:id="@+id/ListName" 
     android:layout_width="344dp" 
     android:layout_height="37dp" 
     android:textColor="@color/blackText" 
     android:background="@color/whiteBackground" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintVertical_bias="0.0" /> 


</android.support.constraint.ConstraintLayout> 

Jede Hilfe wird geschätzt.

+0

Mögliches Duplikat [Wie ein Objekt von einer Android Aktivität auf ein anderes mit Intents schicken? ] (http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – Lingeshwaran

Antwort

2

Sie können Daten zwischen den Aktivitäten passieren ähnliche

Intent intent = new Intent(activity2.this, activity1.class); 
intent.putExtra("message", message); 
startActivity(intent); 

und es mit der anderen Tätigkeit erhalten

Bundle bundle = getIntent().getExtras(); 
String message = bundle.getString("message"); 
+0

@The Abstrakt Glühbirne, da Sie sind neu. .Sie müssen genau bestimmen, was Sie tun müssen. Das Abrufen der Daten und das Anzeigen ist für Sie in Ordnung. aber das wirkliche Problem, das Sie haben, ist, wie man Daten von einer Tätigkeit zur anderen weitergibt. –

+0

Danke Mann. Zumindest hast du versucht, mir bei meiner Frage zu helfen. Schätze es wirklich. –

+0

@The Abstract Lightbulb, Wenn dies für Sie funktioniert, können Sie meine Frage akzeptieren. –

Verwandte Themen