mitchtabian / mvvmexample1 Goto Github PK
View Code? Open in Web Editor NEWA simple of example of MVVM in Android with LiveData and MutableLiveData
A simple of example of MVVM in Android with LiveData and MutableLiveData
Hello Mitch, thanks a ton for sharing this project.
With respect to line 68 in MainActivity, by calling NicePlace constructer in MainActivity, are we not violating the MVVM architecture guideline? If yes then what is the better way to do it? I am new to MVVM and trying to understand the architecture so that I can implement it in my current project.
Thanks.
The repository setValue call works fine with the hard coded data.
It however fails to update the view on first run when loading data from network using Volley.
It populates the views on refresh but not on first run
I dont understand why or where I'm supposed to make change.
Its like the viewModel and the views load first then the data comes in a few seconds later - I can see the data on Toast- but that data is not loaded in the UI.
Using postValue doesnt update the views at all
Sample repository setValue function
public MutableLiveData> getHouseDetails(Context mContext){ this.mContext=mContext; getDatabaseHouseDetails(); MutableLiveData> myData= new MutableLiveData<>(); myData.setValue(dataSet); return myData; }
Sample repository network call getDatabaseHouseDetails(); in volley
@Override public void onSuccessResponse(String response) { Log.e("Response", response); if(response!=null) { try { JSONObject json = new JSONObject(response); //Successfully fetched String sarray = json.getString("house_details"); Toast.makeText(mContext, sarray, Toast.LENGTH_SHORT).show(); JSONArray jsonArray = new JSONArray(sarray); //Clear list to refresh list in every selection for (int i = 0; i < jsonArray.length(); i++) { JSONObject json_list = jsonArray.getJSONObject(i); DecodeHouseDetails houses_array = new DecodeHouseDetails( json_list.getInt("active_identifier"), json_list.getInt("house_id"), json_list.getInt("house_status"), json_list.getString("house_number"), json_list.getString("house_cover"), json_list.getString("house_name"), json_list.getString("longitude"), json_list.getString("latitude") ); dataSet.add(houses_array); } } catch (JSONException e) { e.printStackTrace(); //Dismiss loader isUpdating = false; } } }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.