From a1ae369973ec01e9c1e547bb1f8feb5f00637a2c Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 14 Jul 2014 11:09:23 +0200 Subject: [PATCH] Lista db MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JakieÅ› statyczne dane + Standarodwy Array Adapter --- .../nerull7/mysqlbrowser/DatabaseAdapter.java | 29 +++++++++++++++++++ .../mysqlbrowser/DatabaseFragment.java | 20 +++++++++++-- app/src/main/res/layout/fragment_database.xml | 11 ++++--- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/DatabaseAdapter.java diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseAdapter.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseAdapter.java new file mode 100644 index 0000000..4b9fe91 --- /dev/null +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseAdapter.java @@ -0,0 +1,29 @@ +package info.nerull7.mysqlbrowser; + +import android.content.Context; +import android.widget.ArrayAdapter; +import android.widget.ListAdapter; + +import java.util.HashMap; + +/** + * Created by nerull7 on 14.07.14. + */ +public class DatabaseAdapter extends ArrayAdapter{ + HashMap map = new HashMap(); + + public DatabaseAdapter(Context context, int resource, String[] objects) { + super(context, resource, objects); + } + + @Override + public long getItemId(int position){ + String item = getItem(position); + return map.get(item); + } + + @Override + public boolean hasStableIds(){ + return true; + } +} diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java index 0c37b00..199c860 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java @@ -1,20 +1,36 @@ package info.nerull7.mysqlbrowser; +import android.app.Activity; import android.app.Fragment; import android.os.Bundle; -import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListAdapter; +import android.widget.ListView; + +import info.nerull7.mysqlbrowser.db.DatabaseConnector; /** * Created by nerull7 on 14.07.14. */ public class DatabaseFragment extends Fragment { + ListView databasesListView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ //Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_database, container, false); + View V = inflater.inflate(R.layout.fragment_database, container, false); + databasesListView = (ListView)V.findViewById(R.id.databaseList); + setupListViewDatabase(); + return V; + } + + private void setupListViewDatabase(){ + // TODO not local constuction!!! + DatabaseConnector databaseConnector = new DatabaseConnector("FIXME","FIXME","FIXME"); + ListAdapter listAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, databaseConnector.getDatabases()); + databasesListView.setAdapter(listAdapter); } } diff --git a/app/src/main/res/layout/fragment_database.xml b/app/src/main/res/layout/fragment_database.xml index a673b26..a70411a 100644 --- a/app/src/main/res/layout/fragment_database.xml +++ b/app/src/main/res/layout/fragment_database.xml @@ -8,9 +8,12 @@ android:paddingBottom="@dimen/activity_vertical_margin" tools:context="info.nerull7.mysqlbrowser.DatabaseFragment"> - + + +