I create a list of databases, while trying to find a TextView in another Layout (item.xml), to insert text into it. Why is TextView running empty?

 protected void insertElementOfListFromBase(){ View itemLayout = View.inflate(this, R.layout.item, null); // TextView money_unit = (TextView) itemLayout.findViewById(R.id.money_unit); money_unit.setText("usd"); String[] from = new String[] { SCHETCHIK, STIOMOST }; int[] to = new int[] { R.id.number, R.id.printStoimost }; scAdapter = new SimpleCursorAdapter(this, R.layout.item, cursor, from, to); Spisok = (ListView) findViewById(R.id.spisok); Spisok.setAdapter(scAdapter); } 
  • I'm sorry, I'm new to java, but have you forgotten to turn itemLayout into View? View itemLayout = (View) View.inflate(this, R.layout.item, null); - ikerya

1 answer 1

You create a View :

 View itemLayout = View.inflate(this, R.layout.item, null); // 

Do manipulations with it:

 View itemLayout = View.inflate(this, R.layout.item, null); // TextView money_unit = (TextView) itemLayout.findViewById(R.id.money_unit); money_unit.setText("usd"); 

And do not add it anywhere. You simply do not display it.

  • And how can it be derived? Before that I had text in the xml file in TextView with id money_unit. Now it needs to be changed programmatically. - Alexander
  • @Alexander, give more code. you do not show anything. - Vladyslav Matviienko 6:59 pm