I use several fragments in a swipe tabs. The last one I created shows up correctly in my app but clicking on buttons and edit text doesn't do anything. I think it is the way I created the fragment in studio.
How can I debug this situation.
I add the java code:
public class StoreWords extends Fragment {
public StoreWords() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.store_words_fragment, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initFileSave();
add_w_edit = (EditText) getActivity().findViewById(R.id.add_diffwords_edit);
Button add = (Button) getActivity().findViewById(R.id.add_diffwords);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addWords();
}
});
Button del = (Button) getActivity().findViewById(R.id.remove_diffwords);
del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addWords();
}
});
}
and the layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.bernard.speechparole.StoreWords"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/text_words"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/add_diffwords"
android:layout_marginLeft="10dp"
android:text="@string/add"
android:layout_marginTop="15dp"
android:layout_below="@id/text_words"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/add_diffwords_edit"
android:layout_toRightOf="@id/add_diffwords"
android:layout_marginLeft="30dp"
android:layout_alignBottom="@id/add_diffwords"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/remove_diffwords"
android:text="@string/delete"
android:layout_below="@+id/add_diffwords"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
/>
<ScrollView xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fillViewport="false">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:id="@+id/list_words"
android:layout_marginTop="10dp"
android:layout_below="@id/remove_diffwords"
/>
</ScrollView>
</RelativeLayout>
Many thanks in advance!
Aucun commentaire:
Enregistrer un commentaire