Holen Sie edittext Wert von fragment

Ich bin mit Fragmenten habe ich ein edittext in fragment-und ich möchte Wert in der Haupt-Aktivität.

Dies ist mein fragment-layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#878787" >

        <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="dfgdfgdf"
        android:textSize="20dp"
        android:layout_centerInParent="true"
        android:id="@+id/user_name"/>

    <EditText
    android:id="@+id/message"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
   />

    <Button 
        android:text="Gönder"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="getFromUser"
        android:layout_marginTop="40dp"
        />

</RelativeLayout>

Ich bin laden fragment mit dieser Funktion:

public void startChat(JsonObject user) {
    FrameLayout layout = (FrameLayout)findViewById(R.id.container);
    layout.setVisibility(View.VISIBLE); 
    Bundle bundle = new Bundle();
    bundle.putString("name", user.get("name").getAsString());
    sendTo=user.get("username").getAsString();
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    ConversationFragment conv = new ConversationFragment();
    conv.setArguments(bundle);
    fragmentTransaction.add(R.id.container, conv);
    fragmentTransaction.commit();
    viewPager.setVisibility(View.GONE);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);

}

Und das ist mein fragment-Klasse

public class ConversationFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        String name = getArguments().getString("name");
        View rootView = inflater.inflate(R.layout.fragment_conversation, container, false);
        TextView username=(TextView)rootView.findViewById(R.id.user_name);
        username.setText(name);
        return rootView;
    }
}

Wie Sie sehen können, wenn Sie die Taste drücken, die Haupt-Aktivität führt "getFromUser" - Funktion.Ich will edittext Wert in diese Funktion.Wie kann ich dies tun ?

"Haupttätigkeit "läuft getFromUser" Funktion" macht keinen Sinn, wenn Sie sagen, dass Ihr das fragment-layout. Du meinst getFromUser ist aufgerufen, in das fragment?
ja,ich meine, wenn Benutzer drücken Sie die Taste,getFromUser-Funktion ausgeführt wird,und diese Funktion erklärt in der mainactivity.
Und das ist genau das, was nicht funktioniert, nehme ich an. Die Methode wird nie aufgerufen, auf den button klicken ...
können Sie Ihre mainactivity
Hier voll mainactivity:pastebin.com/WQHgeCdZ

InformationsquelleAutor Tolgay Toklar | 2014-08-05

Schreibe einen Kommentar