I'm starting to develop to android, and I have a big doubt. I know how to work around this problem but I don't like the way I found to do it.
So I have a listview perfectly populated, and have a onItemClickListener:
Using java Syntax Highlighting
- public void onItemClick(AdapterView<?> adapter, View view, int pos, long id) {
- Player player = _game.getPlayer();
- ListView lstview = (ListView) findViewById(R.id.list);
- if(!player.hasPlayed(pos) || !player.hasPlayed() || !_game.hasGameEnded()) {
- LinearLayout layout = (LinearLayout) view;
- layout = (LinearLayout) layout.getChildAt(0);
- TextView txt1 = (TextView) layout.getChildAt(0);
- layout = (LinearLayout) lstview.getChildAt(pos);
- layout = (LinearLayout) layout.getChildAt(0);
- TextView txt2 = (TextView) layout.getChildAt(0);
- System.out.println(txt1.getText());
- System.out.println(txt2.getText());
- txt2.setText("TRETA");
- System.out.println(txt1.getText());
- System.out.println(txt2.getText());
- player.checkPlay(pos);
- player.checkPlay(Player.BONUS);
- _game.changeTab(0);
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
I beg you to ignore the "debugging" code
the thing is, as you see I did a setText on a TextView and the println's next to it confirm i have modified it. But the List is not updated and if I click on the same item again the change to "TRETA" is not there.
I tried to find a solution to this, I don't even know if it's possible to change the view while in the listener. Thanks in advance =)
P.S. the layout of the list item
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <TextView
- android:textSize="25sp"
- android:id="@+id/textlist1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="15px"
- android:layout_marginTop="15px"/>
- <TextView
- android:textSize="25sp"
- android:id="@+id/textlist2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="right"
- android:layout_margin="15px"/>
- </LinearLayout>
- </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

