I’m attempting to create a ListView where I can draw some basic shapes into each item in the ListView. I’ve found many examples using Views/Layouts within a ListView to add an image etc, but am unsure how I would draw into each one using a Canvas or similar. Furthermore these examples seem to all work in slightly different ways, so I was wondering what the best strategy is.
At the moment I just have a Main class which populates the ListView with basic text.
Main.java
public class Main extends Activity {
private ListView listView;
String[] list = {"One","Two","Three"};
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main);
listView = (ListView)findViewById(R.id.ListView1);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
}
}
Now I gather I’ll need change the Adapter bit here, and also write another class which possibly extends View, which I can draw to, then add this as an item in the ListView?
Thanks for your help in advance.
You would need to subclass your ListView to a custom implementation.
You can change the view for each row in the
ListViewby replacing the...with the appropriateViewcode.For example, you can use
SurfaceViewto draw on it.The above code isn’t tested, but hopefully will drive you to the right direction. Make sure you optimize your drawing such as use caching when available, preprocess, etc.