ListViewFragment中的Listview未出现在活动中

时间:2017-10-25 12:54:37

标签: android android-fragments

activity_main.xml FrameLayoutListViewFragment相对fragment。我想在此activity中显示此ListView。但它没有工作<?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"> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_list" /> </android.support.constraint.ConstraintLayout> 没有出现。你知道问题出在哪里吗?

主要活动xml:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // here Im trying to add the fragment A to the activity but the listview is not appearing
        getSupportFragmentManager().
                beginTransaction().add(R.id.fragment_list,new ListViewFragment()).commit();

    }
}

主要活动:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

listview xml:

public class ListViewFragment extends Fragment {
    private ListView editor=null;
    ArrayList<String> items = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View result=inflater.inflate(R.layout.fragment_list, container, false);
        editor=(ListView) (result.findViewById(R.id.listView));
        ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);
        editor.setAdapter(arrayAdapter);
        return result;
    }
}

ListViewFragment:

app/config/services.yml

1 个答案:

答案 0 :(得分:1)

为framelayout添加高度和宽度。

rules: {
        telephone: {
            required: true,
            phoneFR: true,
            remote: {
                  url: 'validate_customer.php',
                  type: "post",
                  data: {
                      telephone: function() {
                          return $('#new-customer-formulaire :input[name="telephone"]').val();
                      },
                      nom: function() {
                          return $('#new-customer-formulaire :input[name="nom"]').val();
                      },
                      prenom: function() {
                          return $('#new-customer-formulaire :input[name="prenom"]').val();
                      }
                  }
              }
        }       
},
messages: {
        telephone: {
            remote: "Un client existe déjà dans la base avec le même nom, prénom et n° de téléphone."
        }
},
errorPlacement: function(error,element) {
         if (error.prop("textContent") == "Un client existe déjà dans la base avec le même nom, prénom et n° de téléphone.") error.insertAfter(element);
         else return true;          
      },

你的listView Fragment也不能将listview作为父布局。所以用框架布局等布局包装它。

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragment_list" />