Changing a listview in onItemClickListener

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Changing a listview in onItemClickListener

Postby N » Thu Apr 23, 2009 8:34 pm

Hello!

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:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onItemClick(AdapterView<?> adapter, View view, int pos, long id) {
  2.  
  3.                                 Player player = _game.getPlayer();
  4.  
  5.                                 ListView lstview = (ListView) findViewById(R.id.list);
  6.  
  7.                                 if(!player.hasPlayed(pos) || !player.hasPlayed() || !_game.hasGameEnded()) {
  8.  
  9.                                         LinearLayout layout = (LinearLayout) view;
  10.  
  11.                                         layout = (LinearLayout) layout.getChildAt(0);
  12.  
  13.                                        
  14.  
  15.                                         TextView txt1 = (TextView) layout.getChildAt(0);
  16.  
  17.                                         layout = (LinearLayout) lstview.getChildAt(pos);
  18.  
  19.                                         layout = (LinearLayout) layout.getChildAt(0);
  20.  
  21.                                         TextView txt2 = (TextView) layout.getChildAt(0);
  22.  
  23.                                        
  24.  
  25.                                         System.out.println(txt1.getText());
  26.  
  27.                                         System.out.println(txt2.getText());
  28.  
  29.                                        
  30.  
  31.                                         txt2.setText("TRETA");
  32.  
  33.                                        
  34.  
  35.                                         System.out.println(txt1.getText());
  36.  
  37.                                         System.out.println(txt2.getText());
  38.  
  39.                                        
  40.  
  41.                                         player.checkPlay(pos);
  42.  
  43.                                         player.checkPlay(Player.BONUS);
  44.  
  45.                                         _game.changeTab(0);
  46.  
  47.                                 }
  48.  
  49.                         }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


I beg you to ignore the "debugging" code :P 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

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.                 android:orientation="vertical"
  6.  
  7.                 android:layout_width="fill_parent"
  8.  
  9.                 android:layout_height="wrap_content"
  10.  
  11.                 >
  12.  
  13.         <LinearLayout
  14.  
  15.                 android:orientation="horizontal"
  16.  
  17.                 android:layout_width="fill_parent"
  18.  
  19.                 android:layout_height="wrap_content">
  20.  
  21.        
  22.  
  23.                         <TextView
  24.  
  25.                                 android:textSize="25sp"
  26.  
  27.                                 android:id="@+id/textlist1"
  28.  
  29.                             android:layout_width="wrap_content"
  30.  
  31.                             android:layout_height="wrap_content"
  32.  
  33.                             android:layout_marginBottom="15px"
  34.  
  35.                             android:layout_marginTop="15px"/>
  36.  
  37.                         <TextView
  38.  
  39.                                 android:textSize="25sp"
  40.  
  41.                                 android:id="@+id/textlist2"
  42.  
  43.                             android:layout_width="fill_parent"
  44.  
  45.                             android:layout_height="wrap_content"
  46.  
  47.                             android:gravity="right"
  48.  
  49.                             android:layout_margin="15px"/>
  50.  
  51.         </LinearLayout>
  52.  
  53. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
N
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 23, 2009 8:31 pm

Top

Postby N » Wed Apr 29, 2009 1:58 pm

this is kind of a bump. But I think I did a post a bit too much complicated... What I want is to when I click a list item, I want it to become grey or change its text.

I tried in the function of the onitemclicklistener and it doesn't change anything on the actual list.

thanks ^^
N
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 23, 2009 8:31 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests