1
I’m facing the problem, below:
I have 2 xml layout: list_single.xml and tela_authorization.xml I have 1 class: Authorization.class
In the Authorization class I have:
setContentView(R.layout.tela_autorizacao);
But I want to change the color of the field KEY_IAESTORNO, only this field is in list_single.xml, I tried to do this:
teste = (TextView) findViewById (R.id.KEY_IAESTORNO);
teste.setTextColor(Color.BLUE);
Of course it didn’t work, it is null, precisely because it is reading the layout-> tela_authorization.xml and the field is in list_single.xml
I’m using an Adapter on the list:
...{
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
NodeList nl2 = doc.getElementsByTagName(KEY_PAI);
list = (ListView) findViewById(R.id.list);
// looping through all item nodes <item>
for (int i = 0; i < nl2.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e2 = (Element) nl2.item(i);
// adding each child node to HashMap key => value
map.put(KEY_IAAUTNUM,
"Nº Autorização: " + parser.getValue(e2, KEY_IAAUTNUM));
map.put(KEY_IAESTORNO, sit + parser.getValue(e2, KEY_IAESTORNO));
map.put(KEY_IAENTNOME,
"Entidade: " + parser.getValue(e2, KEY_IAENTNOME));
map.put(KEY_IAASSNOME,
"Associado: " + parser.getValue(e2, KEY_IAASSNOME));
map.put(KEY_IAASSPORT,
"Portador: " + parser.getValue(e2, KEY_IAASSPORT));
map.put(KEY_IACARTFMT,
"Cartão: " + parser.getValue(e2, KEY_IACARTFMT));
map.put(KEY_IAPARPRIM,
"Prim.Parc.: " + parser.getValue(e2, KEY_IAPARPRIM));
map.put(KEY_IAPARCOUT,
"Demais: " + parser.getValue(e2, KEY_IAPARCOUT));
map.put(KEY_IAQTDPAR,
"Nº Parc.: " + parser.getValue(e2, KEY_IAQTDPAR));
map.put(KEY_IAVALOPE,
"Valor Total: " + parser.getValue(e2, KEY_IAVALOPE));
map.put(KEY_IANOMMES,
"Mês Venc.: " + parser.getValue(e2, KEY_IANOMMES));
map.put(KEY_IAESTNOME,
redetxt + parser.getValue(e2, KEY_IAESTNOME));
map.put(KEY_IAESTCNPJ,
cnpjtxt + parser.getValue(e2, KEY_IAESTCNPJ));
map.put(KEY_IADATA, "Data: " + parser.getValue(e2, KEY_IADATA));
map.put(KEY_IAHORA, "Hora: " + parser.getValue(e2, KEY_IAHORA));
// adding HashList to ArrayList
NUMAUT2 = parser.getValue(e2, KEY_IAAUTNUM);
SITU = parser.getValue(e2, KEY_IAESTORNO);
menuItems.add(map);
}
if (SITU.equals("ESTORNADA")) {
btnEstornar.setVisibility(View.INVISIBLE);
} else {
btnEstornar.setVisibility(View.VISIBLE);
}
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_single_xml, new String[] { KEY_IAAUTNUM,
KEY_IAESTORNO, KEY_IAENTNOME, KEY_IAASSNOME,
KEY_IAASSPORT, KEY_IACARTFMT, KEY_IAPARPRIM,
KEY_IAPARCOUT, KEY_IAQTDPAR, KEY_IAVALOPE,
KEY_IANOMMES, KEY_IAESTNOME, KEY_IAESTCNPJ,
KEY_IADATA, KEY_IAHORA }, new int[] {
R.id.KEY_IAAUTNUM, R.id.KEY_IAASSNOME,
R.id.KEY_IAENTNOME, R.id.KEY_IAASSNOME,
R.id.KEY_IAASSPORT, R.id.KEY_IACARTFMT,
R.id.KEY_IAPARPRIM, R.id.KEY_IAPARCOUT,
R.id.KEY_IAQTDPAR, R.id.KEY_IAVALOPE,
R.id.KEY_IANOMMES, R.id.KEY_IAESTNOME,
R.id.KEY_IAESTCNPJ, R.id.KEY_IADATA,
R.id.KEY_IAHORA
});
TextView estorno =(TextView) adapter.getItem(2);
estorno.setTextColor(Color.RED);
list.setAdapter(adapter);
}
Someone knows how to do?
Rogers, your question is a little confusing, so I understand you want to retrieve the
View
main of itsActivity
right (if not, try to clarify a little better)? if you do:findViewById(android.R.id.content)
within yourActivity
orgetView
in hisFragment
, it returns the root of itsView
. From thatView
you can search for the other elements. If Textview is inside aListView
you need: Or access the data that feeds the list item (byAdapter
) or to seek a child, using theViewGroup.childAt
.– Wakim
@Wakim edited, you can understand?
– Rogers Corrêa
I think I understand, you want to change only one, given a position, or you want to change all (a
View
that is within the layout of theListView
that has idKEY_IAESTORNO
)?– Wakim
just the color of a @Wakin,
– Rogers Corrêa
Only the color of KEY_IAESTORNO understood?
– Rogers Corrêa
Got it, I’m putting together an answer with a few details.
– Wakim