Reputation: 63
Hi my program should update the listview based on which radiobutton is selected and show all records of the one of the two tables.
As far as I can tell the records are in fact populated, it seems not to be refreshing the listview itself. Please help me solve this problem. Thanks in advance
Here is my code:
In onCreate:
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
RadioButton rb1 = (RadioButton) findViewById(R.id.radio0);
RadioButton rb2 = (RadioButton) findViewById(R.id.radio1);
switch(checkedId)
{
case R.id.radio0:
{
rb2.setChecked(false);
// populateList();
// ListView lview = (ListView) findViewById(R.id.listView1);
// lview.invalidateViews();
}
break;
case R.id.radio1:
{
rb1.setChecked(false);
// populateList();
// ListView lview = (ListView) findViewById(R.id.listView1);
// lview.invalidateViews();
}
break;
}
populateList();
// ListView lview = (ListView) findViewById(R.id.listView1);
// lview.updateViewLayout();
}
});
Methods used:
private void populateList()
{
RadioButton rb1 = (RadioButton) findViewById(R.id.radio0);
RadioButton rb2 = (RadioButton) findViewById(R.id.radio1);
EditText mEdit1 = (EditText)findViewById(R.id.editText1);
list = new ArrayList<HashMap>();
insertConstant();
if(rb1.isChecked() == true)
{
auditds = new ProjectAuditingDataSource(this);
auditds.open();
List<DataCapture> auditValues = auditds.getAllAudits();
ArrayAdapter<DataCapture> auditadapter = new ArrayAdapter<DataCapture>(this,
android.R.layout.simple_list_item_1, auditValues);
int countaudits = 0;
int auditsize = auditValues.size();
while (countaudits < auditsize)
{
HashMap temp2 = new HashMap();
temp2.put(FIRST_COLUMN,auditValues.get(countaudits).getId());
temp2.put(SECOND_COLUMN,auditValues.get(countaudits).getName());
temp2.put(THIRD_COLUMN, auditValues.get(countaudits).getXcoordinate());
temp2.put(FOURTH_COLUMN, auditValues.get(countaudits).getVMstartdate());
list.add(temp2);
countaudits++;
}
}
//////////////////////////////////////////////////////////////////////
if(rb2.isChecked() == true)
{
assetsds = new AssetsDataSource(this);
assetsds.open();
List<Assets> assetValues = assetsds.getAllAssets();
ArrayAdapter<Assets> assetadapter = new ArrayAdapter<Assets>(this,
android.R.layout.simple_list_item_1, assetValues);
int countassets = 0;
int size = assetValues.size();
while (countassets < size)
{
HashMap temp = new HashMap();
temp.put(FIRST_COLUMN,assetValues.get(countassets).getAssetId());
temp.put(SECOND_COLUMN,assetValues.get(countassets).getAssetDescription());
temp.put(THIRD_COLUMN, assetValues.get(countassets).getInspectorId());
temp.put(FOURTH_COLUMN,"insert time here");
list.add(temp);
countassets++;
}
}
ListView lview = (ListView) findViewById(R.id.listView1);
lview.invalidateViews();
}
public void insertConstant()
{
list.clear();
HashMap temp0 = new HashMap();
temp0.put(FIRST_COLUMN, com.example.demoapplication1.Constant.FIRST_COLUMN);
temp0.put(SECOND_COLUMN, com.example.demoapplication1.Constant.SECOND_COLUMN);
temp0.put(THIRD_COLUMN, com.example.demoapplication1.Constant.THIRD_COLUMN);
temp0.put(FOURTH_COLUMN, com.example.demoapplication1.Constant.FOURTH_COLUMN);
list.add(temp0);
}
Let me know if you require more information
Upvotes: 0
Views: 394
Reputation: 2664
set the Adapter to the listview
You need to call the notifyDataSetChanged() of Adapter when you need the listview to be updated
Upvotes: 0
Reputation: 1335
You missed setting the adapter on the listview :
lview.setAdapter(assetadapter);
Upvotes: 1