You will need to customize the adapter I have something that is roughly what you want to follow the code
public class AdapterList extends ArrayAdapter<String> {
private String[] values;
private int mSelectedItem;
private Context context;
public AdapterList(Context context, String[] values) {
super(context, R.layout.layout_navigation_drawer);
this.values = values;
this.context = context;
}
public int getmSelectedItem() {
return mSelectedItem;
}
public void setmSelectedItem(int mSelectedItem) {
this.mSelectedItem = mSelectedItem;
}
@Override
public int getCount() {
return this.values.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.layout_navigation_drawer, parent, false);
TextView txt = (TextView) rowView.findViewById(R.id.txt_nav_drawer);
txt.setText(values[position]);
if(position == mSelectedItem){
txt.setTextColor(getContext().getResources().getColor(android.R.color.white));
txt.setBackgroundColor(getContext().getResources().getColor(R.color.red_color));
}else {
txt.setTextColor(getContext().getResources().getColor(R.color.green_color));
}
return rowView;
}
}
layout_navigation_drawer.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txt_nav_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:text="algo"
android:textColor="@drawable/txt_selected"
android:textSize="21dp" />
In the getView method I have an if that checks if the current position is the same as my selected item (mSelectedItem) if yes I change the color of that line. See that I created a method to pass the position that was clicked on your case will be the position of the name that you will make the registration.
What you need to do in the onActivityResult is to verify that the registration has actually been made and to move the position of the name that was clicked to register.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lv = new ListView(this);
AdapterList adapter = new AdapterList(this, vetornomes);
lv.setAdapter(adapter);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//verificar se o cadastro foi feito caso sim o seguinte codigo deve ser adicionado
adapter.setmSelectedItem(posicao);
//para que seja atualizado a cor vc deve chamar o seguinte método
adapter.notifyDataSetChanged();
}