· 7 years ago · Feb 12, 2019, 01:14 PM
1import android.content.ContentValues;
2import android.content.Context;
3import android.database.Cursor;
4import android.database.SQLException;
5import android.database.sqlite.SQLiteDatabase;
6import android.database.sqlite.SQLiteOpenHelper;
7
8public class SQLDatabase {
9
10 public static final String KEY_MOVENAME = "movename";
11 public static final String KEY_MOVEID = "_moveid";
12 public static final String KEY_MOVEDATE = "movedate";
13
14 private static final String DATABASE_NAME = "mymovingfriend";
15 private static final int DATABASE_VERSION = 1;
16
17 private static final String DATABASE_TABLE = "movingname";
18
19 public static final String CREATE_TABLE = "CREATE TABLE " + DATABASE_TABLE + " (" + KEY_MOVEID +
20 " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_MOVEDATE + " TEXT NOT NULL, " + KEY_MOVENAME + " TEXT NOT NULL);";
21
22
23 private DbHelper ourHelper;
24 private final Context ourContext;
25 private SQLiteDatabase ourDatabase;
26
27 private static class DbHelper extends SQLiteOpenHelper{
28
29 public DbHelper(Context context) {
30 super(context, DATABASE_NAME, null, DATABASE_VERSION);
31 // TODO Auto-generated constructor stub
32 }
33
34 @Override
35 public void onCreate(SQLiteDatabase db) {
36 // TODO Auto-generated method stub
37 db.execSQL(CREATE_TABLE);
38 }
39
40 @Override
41 public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
42 // TODO Auto-generated method stub
43 db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
44 onCreate(db);
45 }
46 }
47
48 public SQLDatabase(Context c){
49 ourContext = c;
50 }
51
52 public SQLDatabase open() throws SQLException{
53 ourHelper = new DbHelper(ourContext);
54 ourDatabase = ourHelper.getWritableDatabase();
55 return this;
56 }
57
58 public void close(){
59 ourHelper.close();
60 }
61
62 public long createMove(String smovename){
63 ContentValues cv = new ContentValues();
64 cv.put(KEY_MOVENAME, smovename);
65 return ourDatabase.insert(DATABASE_TABLE, null, cv);
66 }
67
68 public String getMove(){
69 String[] column = new String[]{KEY_MOVENAME};
70 Cursor c = ourDatabase.query(DATABASE_TABLE, column, null, null, null, null, null);
71 String result = "";
72
73 int iMove = c.getColumnIndex(KEY_MOVENAME);
74
75 for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
76 result = result + c.getString(iMove) + "n";
77 }
78 c.close();
79 return result;
80 }
81
82}
83
84import android.app.ListActivity;
85import android.os.Bundle;
86import android.view.View;
87import android.widget.ListView;
88
89public class ListMovingNames extends ListActivity {
90 ListView MoveList;
91
92 @Override
93 protected void onCreate(Bundle savedInstanceState) {
94 // TODO Auto-generated method stub
95 super.onCreate(savedInstanceState);
96 setContentView(R.layout.selectorcreatemove);
97
98 MoveList = (ListView) findViewById(R.id.lvMoveItems);
99
100 }
101
102 @Override
103 protected void onListItemClick(ListView l, View v, int position, long id) {
104 // TODO Auto-generated method stub
105 super.onListItemClick(l, v, position, id);
106 }
107
108}
109
110public List<App_List> getAppList(String appclass){
111 List<App_List> App_ListView = new ArrayList<App_List>();
112 String AppTable_Name="favorite_apps";
113 String AppList_Query="SELECT * FROM " + AppTable_Name +" WHERE appclass = "+ "'"+appclass+"'";
114 SQLiteDatabase db = this.getReadableDatabase();
115 Cursor cursor = db.rawQuery(AppList_Query, null);
116 if (cursor.moveToFirst()){
117 do{
118 App_List mAppList = new App_List();
119 if(cursor.getString(7).equalsIgnoreCase("local")){
120 // if application is from local server also take the version
121 mAppList.setVersion(cursor.getString(0));
122 }
123 mAppList.setApp_Name(cursor.getString(3));
124 mAppList.setApp_Description(cursor.getString(4));
125 mAppList.setApp_Link(cursor.getString(6));
126 mAppList.setPlace(cursor.getString(7));//place is added here
127 mAppList.setApp_Pkg(cursor.getString(1));
128 App_ListView.add(mAppList);
129 }while (cursor.moveToNext());
130 }
131 db.close();
132 return App_ListView;
133
134public class App_List {
135private String App_Name;
136private String App_Description;
137private String App_Link;
138private String App_Pkg;
139public String getPlace() {
140 return place;
141}
142public void setPlace(String place) {
143 this.place = place;
144}
145private String Version;
146private String place;
147
148public String getVersion() {
149 return Version;
150}
151public void setVersion(String version) {
152 Version = version;
153}
154public String getApp_Name() {
155 return App_Name;
156}
157public void setApp_Name(String app_Name) {
158 App_Name = app_Name;
159}
160public String getApp_Description() {
161 return App_Description;
162}
163public void setApp_Description(String app_Description) {
164 App_Description = app_Description;
165}
166public String getApp_Link() {
167 return App_Link;
168}
169public void setApp_Link(String app_Link) {
170 App_Link = app_Link;
171}
172public String getApp_Pkg() {
173 return App_Pkg;
174}
175public void setApp_Pkg(String app_Pkg) {
176 App_Pkg = app_Pkg;
177}
178
179@Override
180public View getView(int position, View convertView, ViewGroup parent) {
181 // TODO Auto-generated method stub
182 View mView=convertView;
183 if (convertView == null)
184 mView = inflater.inflate(R.layout.app_adapter, parent,false);
185 App_List mAppList= mList.get(position);
186 ((TextView) mView.findViewById(R.id.textView_appName)).setText(mAppList.getApp_Name());
187 ((TextView) mView.findViewById(R.id.textView_appDescription)).setText(mAppList.getApp_Description());