Currently my codes is working except for 2 issues.
Issues
- Only able to add name and rating once
- Can only update the ratings not the name
Below is the source code I feel that is giving me the issue, but I have tried editing the codes, but the result is still the same. If anyone can take some time to take a look, I will appreciate it.
If not, could you please provide some links that are related? I have been trying to get the code working for 2 days now and it is still giving me the same problem. I came here hoping that someone can help me.
MainActivity.java
lvInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
txtName.setText(results.get(position).getName());
ratingBar.setRating(results.get(position).getRating());
}
});
DisplayAll();
}
public void DisplayAll() {
results = db.getAllResults();
ArrayofName.clear();
for (Result rs : results) {
ArrayofName.add(rs.getId() + ".\t" + rs.getName() + ".\t" + rs.getRating());
}
dbAdapter.notifyDataSetChanged();
txtName.setText("");
ratingBar.setRating(5);
}
public void AddResult(View view) {
if ((txtName.getText().length() == 0) || (ratingBar.getRating() == 0) )
Toast.makeText(this, "Please enter the name and rating to be added!", Toast.LENGTH_LONG).show();
else {
Result tmp = new Result(txtName.getText().toString(),
ratingBar.getRating() );
db.addResult(tmp);
DisplayAll();
Toast.makeText(this, "Results Added!", Toast.LENGTH_LONG).show();
}
}
public void UpdateResult(View view) {
if ((txtName.getText().length() == 0) || (ratingBar.getRating() == 0) )
Toast.makeText(this, "Please select result to be updated!", Toast.LENGTH_LONG).show();
else {
Result tmp = new Result(txtName.getText().toString(),ratingBar.getRating() );
db.updateResult(tmp);
DisplayAll();
Toast.makeText(this, "Result Updated!", Toast.LENGTH_LONG).show();
}
}
}
Aucun commentaire:
Enregistrer un commentaire