I have tried any method
this is my DBController.java
public class DBController extends SQLiteOpenHelper
{
public DBController(Context applicationcontext)
{
super(applicationcontext, "user.db", null, 1);
}
//Creates Table
@Override
public void onCreate(SQLiteDatabase database)
{
String query;
query = "CREATE TABLE users ( userId INTEGER, userName TEXT)";
database.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase database, int version_old, int current_version)
{
String query;
query = "DROP TABLE IF EXISTS users";
database.execSQL(query);
onCreate(database);
}
/**
* Inserts User into SQLite DB
* @param queryValues
*/
public void insertUser(HashMap<String, String> queryValues)
{
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("userId", queryValues.get("userId"));
values.put("userName", queryValues.get("userName"));
database.insert("users", null, values);
database.close();
}
/**
* Get list of Users from SQLite DB as Array List
* @return
*/
public ArrayList<HashMap<String, String>> getAllUsers()
{
ArrayList<HashMap<String, String>> usersList;
usersList = new ArrayList<HashMap<String, String>>();
String selectQuery = "SELECT * FROM users";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
{
do
{
HashMap<String, String> map = new HashMap<String, String>();
String idnya = cursor.getString(0);
if (idnya.equals("36"))
{
map.put("userId", "My Id");
map.put("userName", "My Username");
Context context=null;
ViewGroup parent=null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.view_user_entry, parent, true);
LinearLayout bg = (LinearLayout) v.findViewById(R.id.wrapper);
bg.setBackgroundResource(R.drawable.bubble_yellow);
}
else
{
map.put("userId", cursor.getString(0));
map.put("userName", cursor.getString(1));
}
usersList.add(map);
}
while (cursor.moveToNext());
}
database.close();
return usersList;
}
}
and this is MainActivity.java
public class MainActivity extends ActionBarActivity
{
DBController controller = new DBController(this);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get User records from SQLite DB
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
// If users exists in SQLite DB
if (userList.size() != 0)
{
ListAdapter adapter = new SimpleAdapter(MainActivity.this, userList, R.layout.view_user_entry, new String[] {
"userId", "userName" }, new int[] { R.id.userId, R.id.userName });
ListView myList = (ListView) findViewById(android.R.id.list);
myList.setAdapter(adapter);
}
Intent alarmIntent = new Intent(getApplicationContext(), SampleBC.class);
// Pending Intent Object
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
// Alarm Manager calls BroadCast for every Ten seconds (10 * 1000), BroadCase further calls service to check if new records are inserted in
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 5000, 10 * 1000, pendingIntent);
}
// Options Menu (ActionBar Menu)
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// When Options Menu is selected
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here.
int id = item.getItemId();
// When Sync action button is clicked
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is view-user_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/wrapper"
android:background="@drawable/bubble_green" >
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="dp"
android:paddingLeft="0dip"
android:paddingTop="0dip"
android:textColor="@android:color/primary_text_light"
android:textSize="14sp"
/>
<TextView
android:id="@+id/userId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
here is my error
Context context=null;
ViewGroup parent=null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.view_user_entry, parent, true);
LinearLayout bg = (LinearLayout) v.findViewById(R.id.wrapper);
bg.setBackgroundResource(R.drawable.bubble_yellow);
when I running application, it says force closed. I don't know what should i do, because all method have tried, but still force closed.
Thank you very much.