I'm making a listview that contains a custom layout. Inside the custom layout is an imageview. When I use Listview lv.setonclick listener it provides me with a variable View that I can use to manipulate the drawable like so. lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View listview,
int position, long arg3) {
ImageView pincolor = (ImageView) listview
.findViewById(R.id.ivimtrackingpin);
pincolor.setImageResource(R.drawable.pinred);
However when I want to make another function I don't have this View listview variable. How do I get it so that I can do the same thing just outside of the onclicklistener? Thanks
EDIT here is my list view and the adapter
SpecialAdapter adapter = new SpecialAdapter(this, list,
R.layout.imtracking_row_text, new String[] { "name",
"location" }, new int[] { R.id.tvImtrackingName,
R.id.tvImtrackingLocation });
HashMap<String, String> temp = new HashMap<String, String>();
JSONObject user = tracking_users.getJSONObject(i);
temp.put("name", user.getString("full_name"));
// upload location time
temp.put("location", user.getString("last_updated_at"));
list.add(temp);
lv.setAdapter(adapter);
public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[]{R.drawable.row_background_grey, R.drawable.row_background_white};
public SpecialAdapter(Context context,
ArrayList<HashMap<String, String>> list, int resource,
String[] from, int[] to) {
super(context, list, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundResource(colors[colorPos]);
return view;
}
}