4

am using a simple adapter to show set of strings in different text fields in a listview... i want when i click a particular content in that listview, some textview should be invisible.. how to do that...

my code is

String[] from = new String[] {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN"};

int[] to = new int[] { R.id.textView_1, R.id.textView_2, R.id.textView_3, R.id.textView_4, R.id.textView_5, R.id.textView_6, R.id.textView_7};


Adapter adapter = new SimpleAdapter(this, Maps, R.layout.search, from, to);
ListView lvSearch = (ListView) findViewById(R.id.listView_SearchResult);
lvSearchResult.setAdapter(adapter);

here on click

R.id.textView_5, R.id.textView_6, R.id.textView_7

should be invisible

sietschie
  • 7,425
  • 3
  • 33
  • 54
786
  • 71
  • 1
  • 2
  • 6

4 Answers4

6

Not sure what exactly you're looking for here, but if what you're trying to do is simply hide the TextView, you could do the following:

TextView txtView = (TextView)findViewById(R.id.textView_6);
txtView.setVisibility(View.GONE)

We can try and help you further if you provide us with a bit more information.

Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
5

Set the attribute android:visibility="gone" for the TextViews R.id.textView_5, R.id.textView_6, R.id.textView_7 in the layout layout.search

For your example I guess the result should look like:

<TextView android:id="@+id/textView_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hidden"
        android:visibility="gone"/>
Alexander Egger
  • 5,132
  • 1
  • 28
  • 42
4

There is a method inside SimpleAdapter for that. It's called ViewBinder. Try to include this line of code immediately after SimpleAdapter adapter = new SimpleAdapter(this, Maps, R.layout.search, from, to); and before setListAdapter(adapter);.

SimpleAdapter.ViewBinder binder = new SimpleAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Object object, String value) {
        System.out.println("view= "+view);
        System.out.println("view.toString()= "+ view.toString());
        System.out.println("view.getId()= "+ view.getId());
        System.out.println("view.getVisibility()= "+ view.getVisibility());
        System.out.println("view.equals((TextView) view.findViewById(R.id. textView_5))= "+ view.equals((TextView) view.findViewById(R.id.textView_5)));
        if (view.equals((TextView) view.findViewById(R.id.textView_5))) {
            TextView textView_five = (TextView) view.findViewById(R.id. textView_5);
            //Change color/answer/etc for textView_5
        }

        //OR
        if (view instanceof TextView) {
            //Do stuff
            return true;
        }

        return false;
    }
};

adapter.setViewBinder(binder);

setListAdapter(adapter);    

The setViewValue() method will be called for each R.id.textView_1, R.id.textView_2, R.id.textView_3, R.id.textView_4, R.id.textView_5, R.id.textView_6, R.id.textView_7 that you have in adapter. The setViewValue() method will be called each View/each time one of the above R.ids is being drawn.

Generic Bot
  • 309
  • 1
  • 4
  • 8
Gene
  • 10,819
  • 1
  • 66
  • 58
0

override @getView method and implements it custum view

  @override
  public View getView (int position, View convertView, ViewGroup parent){
   if( convertView == null ){
    //initialize
    convertView = inflater.inflate(R.layout.list_items, parent, false);
   }
   //Here you can hide or visible 
   return convertView;
   }