0

Is there a view in android, that can store one object and display the object's toString() return value like a TextView?

Or do I have to mimic the behaviour in taking a ListView and ensure that only one item is in its adapter?

I need this, because I use drag & drop to move objects around and I need a view, that can display and store one of the objects.

Thank you!

user1809923
  • 1,235
  • 3
  • 12
  • 27

2 Answers2

1

There is no such view. Depending on your requirements, you have to implement this functionality.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
0

yes, there is such a view and you already mentioned it. it's called TextView, and you'd use it like this,

TextView tv = (TextView)findObjectById(R.id.tv);
tv.setText(myObject.toString());

if you don't like like that, extend TextView like this,

class ToStringView extends TextView { 
  ...
  public void setObject(Object o) { setText(o.toString()); }
}
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • I went with your second option, since apparently there is no buildin view which directly offers the functionality. The following like might be helpful to others, when they want to include their own textview: http://stackoverflow.com/questions/5514281/how-to-use-own-view-in-layout – user1809923 Jan 23 '13 at 16:53