Sunday, July 3, 2011

[android-developers] Modify listview item child views with adapter and getview()

Does calling notifyOnDataSetChanged() will restore previous settings
for each of the items, that previously had their child views
visibility set to View.VISIBLE (supposing item is clicked before) and
then set the visibility to View.VISIBLE on the item that is currently
clicked?

See the code below:
------------------------This is the onItemClickListener of the
listview--------------------------------------------------------
listView.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View viewItem, int
position, long arg3) {

click=true;
cur.notifyDataSetChanged();


viewItem=parent.getChildAt(position);

((Button)viewItem.findViewById(R.id.gotherefav)).setVisibility(View.VISIBLE);

((Button)viewItem.findViewById(R.id.removefav)).setVisibility(View.VISIBLE);

TextView text = (TextView)viewItem.findViewById(R.id.item);
ime = text.getText();
cur.notifyDataSetInvalidated();
}});
-------------------------------------This is the
getView()----------------------------------------------------------------------------

public View getView(int position, View convertView, ViewGroup parent)
{

if (convertView == null) {
LayoutInflater vi =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.temp2, null);
}

String t = items.get(position);
if (t != null) {

TextView itemText = (TextView)
convertView.findViewById(R.id.item);

itemText.setText(t);
itemText.invalidate();
itemText.setTextSize(20.0f);

}

((Button)convertView.findViewById(R.id.gotherefav)).setVisibility(View.INVISIBLE);

((Button)convertView.findViewById(R.id.removefav)).setVisibility(View.INVISIBLE);


return convertView;

}
}
------------------------------------------------------------------------------------

Do i call prematurely notifyDatasetchanged() in
listviewonclicklistener or dataSetInvalidated? Why it does not show
the buttons(child views) when the item is clicked? Please, guide me,
what i'm doing wrong?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment