0
I’m trying to change the color of the text of this listview that I did by following some examples on the internet, but the most I could was the comment from row 39* txt.setTextColor(Color.GREEN); The problem is that this only changes the color when clicked and still the color does not return to normal. : / I need a solution to make the appearance a little more beautiful, I’ve tried several tutorials from other site but they did not work very well.
I would like a solution that is as simple as possible for studies. But anything that works is also worth. :)
The Main class:
public class Main extends Activity {
public ListView list;
static int numPerildo = 2;
static String perildoAtual;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, Cursos);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
TextView txt = (TextView) view; //funciona
//txt.setTextColor(Color.GREEN);
//TextView txt = (TextView) view.findViewById(R.id.post);
//mensagem.setTitle("Escolha qual o perildo");
//mensagem.setMessage( txt.getText().toString() );
//mensagem.setNeutralButton("OK", null);
//txt.setTextColor(color.white);
//trace("Item selecionado : " + position);
if(txt.getText().toString().equals("valor 1")){
numPerildo = 5;
telaPerildo();
}
perildoAtual = txt.getText().toString();
}
});
}
public void telaPerildo(){
Intent i = new Intent(this, Periodo.class);
startActivity(i);
}
static final String[] Cursos = new String[] {"valor 1",
"valor 2",
"valor 3"};
public void toast (String msg){
Toast.makeText (getApplicationContext(), msg, Toast.LENGTH_SHORT).show ();
}
private void trace (String msg){
toast (msg);
}
}
A Main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/azulClaro"
tools:context="${packageName}.${activityClass}" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Escolha o seu curso:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text" >
</ListView>
</RelativeLayout>
Huumm, now yes it’s making sense, thank you so much @Wakim ! I prefer the second option and it worked perfectly, you know what I mean!
– Dannark
I’ve made some considerations to help.
– Wakim
Dannark follows @Walkim’s considerations (1st option) that sooner or later you will need to create your own adapter, so you can use your objects in the adapter. Take advantage of the features of Java and Android XML objects.
– Jorge B.
Thanks a lot :)
– Dannark