Skip to content

Instantly share code, notes, and snippets.

@kevinjam
Created April 18, 2016 15:49
Show Gist options
  • Save kevinjam/411f8b732bfc2613f89e01ba6931fd28 to your computer and use it in GitHub Desktop.
Save kevinjam/411f8b732bfc2613f89e01ba6931fd28 to your computer and use it in GitHub Desktop.
?xml version="1.0" encoding="utf-8"?>
<manifest package="com.kevinjanvier.latterglory.sugarorm"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="com.orm.SugarApp"><!--Your package-->
<!--Sugra Orm-->
<!-- All you need to do is, specify SugarApp as your application class in AndroidManifest.xml. You do that by changing the android:name attribute of the application
-->
<meta-data android:name="DATABASE" android:value="kevin_db.db" /><!--Name of the generated sqlite database file. eg: app_name.db-->
<meta-data android:name="VERSION" android:value="2" /><!--Version of your database schema.-->
<meta-data android:name="QUERY_LOG" android:value="true" /><!--Logs the generated Select queries.-->
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.kevinjanvier.latterglory.sugarorm" /><!--Specify your package name
-->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>:
compile 'com.github.satyan:sugar:1.4'
List<Todo> names;
ArrayAdapter<Todo> adapter;
ListView listView;
EditText user, first, country;
Button save;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
user = (EditText) findViewById(R.id.username);
first = (EditText) findViewById(R.id.firstname);
country = (EditText) findViewById(R.id.country);
save = (Button) findViewById(R.id.savebtn);
save.setOnClickListener(this);
names = Todo.listAll(Todo.class);
adapter = new ArrayAdapter<Todo>(this, R.layout.item_users,R.id.User, names);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
}
@Override
public void onClick(View v) {
// Load Entity From The database
Todo todo = new Todo();
todo.setFirstname(first.getText().toString().trim());
todo.setUsername(user.getText().toString().trim());
todo.setCountry(country.getText().toString().trim());
//Save From the Db
todo.save();
adapter.add(todo);
user.getText().clear();
first.getText().clear();
country.getText().clear();
Toast.makeText(this,"You have save"+ todo, Toast.LENGTH_LONG).show();
}
public class Todo extends SugarRecord{
String username;
String firstname;
String country;
public Todo(){
}
public Todo(String username, String firstname, String country){
this.username = username;
this.firstname = firstname;
this.country = country;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
//Here You can add more fields as you wish
@Override
public String toString() {
return firstname;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment