从mysql数据库中检索所有数据并在listview android中显示

时间:2017-04-17 18:43:09

标签: android mysql listview android-fragments mysqli

我刚刚创建了一个应用程序,它使用Custom Listview适配器将一些静态数据显示为listview。我需要使用mysql数据库中的数据填充listview,其中数据库的每一行应提供给每个listview行。

列表视图的数据在页面活动中给出:

public class Menu1 extends Fragment {
    private ArrayList<Property> rentalProperties = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //returning our layout file
        //change R.layout.yourlayoutfilename for each of your fragments
        View rootView = inflater.inflate(R.layout.fragment_all, container, false);
        rentalProperties.add(new Property(10, "Smith Street", "Sydney", "NSW", "A large 3 bedroom apartment right in the heart of Sydney! A rare find, with 3 bedrooms and a secured car park.", 450.00, "property_image_1", 3, 1, 1, false));
        rentalProperties.add(new Property(66, "King Street", "Sydney", "NSW", "A fully furnished studio apartment overlooking the harbour. Minutes from the CBD and next to transport, this is a perfect set-up for city living.", 320.00, "property_image_2", 1, 1, 1, false));
        rentalProperties.add(new Property(1, "Liverpool Road", "Liverpool", "NSW", "A standard 3 bedroom house in the suburbs. With room for several cars and right next to shops this is perfect for new families.", 360.00, "property_image_3", 3, 2, 2, true));
      //  rentalProperties.add(new Property(567, "Sunny Street", "Gold Coast", "QLD", "Come and see this amazing studio apartment in the heart of the gold coast, featuring stunning waterfront views.", 360.00, "property_image_4" , 1, 1, 1, false));

我们在这里可以看到,

  

rentalProperties.add(新物业(10,“史密斯街”,“悉尼”,“新南威尔士州”,   “一个大的,有3间卧室和一个安全的停车场。”,450.00,   “property_image_1”,3,1,1,false));

此代码将为单个列表视图生成数据。我的目标是从数据库中检索数据并给出每行数据而不是这里给出的虚拟数据,比如'史密斯街'...... 请帮助我,如果可能的话详细解释。此致...

0 个答案:

没有答案
相关问题