1

I am trying to update a single row (two textviews) in a listview by changing the visibility of the second textview from "gone" to "visible".

Here is the XML for the custom layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/userlistlayout"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#000000"/>
    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" android:visibility="gone"/>

I am using an arrayadapter to bind the data from a string[] to the listview. This is working perfectly. Where I am running into problems is pushing the change back to the screen.

Here is the test code I have for my array adapter and the attempt to set the visiblity on a single row's second textview.

searchResults = (ListView) findViewById(R.id.listView1);    
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.userlist, R.id.textView1,names);

searchResults.setAdapter(adapter);
//all the code above this point works perfectly to populate the listview (textview1) 
with the names passed in from the names string[]                    

LinearLayout hold = (LinearLayout) adapter.getView(2, null, null);
TextView hold2 = (TextView) hold.findViewById(R.id.textView2);
hold2.setVisibility(TextView.VISIBLE);

adapter.notifyDataSetChanged();

searchResults.invalidateViews();

This code does not throw any kind of error, however, i am not getting any kind of update on the listview. I am not sure what I am doing wrong or what step I am missing to get the visibility change made to hold2 to be pushed back into the adapter/listview and updated on the screen whereby the second textview on that particular row will be visible.

Once I get this working I want to trigger it onclick.

Any help would be much appreciated.

Derek
  • 43
  • 1
  • 4

1 Answers1

0

its pretty late but here is my answer ;

in your code , you are just doing refreshing in the oncreate , just once. but you have the listen for user for all the time , so you can do it

listview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                final int position, long id) {

            //here 

        }
    });

now you can use adapter.notifyDataSetChanged(); in the on click .

but i think you should check these posts

this

that

also there is a different solution, we use animations

in the global of adapter

  public View selectedView ,previousView ;
  public Animation fadeIn , fadeOut;

in the adapter's getview

    try {
                if (previousView != v){                             
                    Animation b = AnimationUtils.loadAnimation(context, R.anim.fadein);
                    b.setDuration(177);
                    b.setFillAfter(true);
                    previousView.startAnimation(b);
                    previousView.findViewById(R.id.llTicketViewOnClickContainer).setVisibility(View.GONE);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

//..... some other code




//just before closing of get view
previousView =v
 }
Community
  • 1
  • 1
Alp
  • 1,863
  • 1
  • 20
  • 38