0

Im trying to make my listview update the colour of the "android.R.id.text1" line (top line of the two listview lines) whenever you click the "Enrollment" button. The class also calls colourCodeCourses() on create and that works fine to correctly display the course colours, however when I click the enrollment button no matter what I've tried I can't get my listview to update the colour of the text until I hit "back" and reopen the Activities view. At that point, the listview appears in the correct colour. (These aren't all the methods and instance variables, just the relevant ones). Any help is appreciated.

private ListView listView;
private ArrayAdapter<Course> courseArrayAdapter;
private AccessEnrollment accessEnroll;
private ArrayList<Course> comparisonList;
private Degree degree;

public void buttonEnrollOnClick(View v){
    int position = listView.getCheckedItemPosition();
    Course course = (Course)listView.getItemAtPosition(position);
    TextView courseID = (TextView)listView.findViewById(android.R.id.text1);
    TextView courseName = (TextView)listView.findViewById(android.R.id.text2);

    accessEnroll.insertEnrollmentData(course);
    degree.addCourse(course);

    colourCodeCourses(position, courseID, courseName, true);

    courseArrayAdapter.notifyDataSetChanged();

}


private void colourCodeCourses(int position, TextView courseTitle, TextView courseDescription, boolean newEnroll) {
    displayGrade = "";

    if(!newEnroll){
    if (degree.getCourse(position).getGrade()!="N")
    {
        displayGrade = " {" + degree.getCourse(position).getGrade() + "} ";
    }
    courseTitle.setText(degree.getCourse(position).getCourseID()+ " " + displayGrade );
    courseDescription.setText(degree.getCourse(position).getCourseName());

    if (comparisonList.contains(degree.getCourse(position)))
    {
        if (degree.getCourse(position).getGrade().equals("IP")){
            courseTitle.setTextColor(Color.rgb(0,0,160));
        }else{
        courseTitle.setTextColor(Color.rgb(0, 160, 0));
        }
    }
    else
    {
        courseTitle.setTextColor(Color.rgb(160, 0, 0));
    }

    }else{
        courseTitle.setTextColor(Color.BLUE);
    }
}
Tyler
  • 25
  • 9

1 Answers1

0

You have to set your styles in ListView Adapter's getView() method. As far as I can see now you are just searching for a TextView inside a ListView and set its text color. You should store selected state in your Adapter and set the color of your TextView's accordingly.

Here is the link to go: http://www.vogella.com/tutorials/AndroidListView/article.html

agamov
  • 4,407
  • 1
  • 27
  • 31