カスタムレイアウトを含むリストビューを作成しています。カスタムレイアウトの中にはimageviewがあります。Listview lv.setonclickリスナーを使用すると、そのようにドローアブルを操作するために使用できる変数Viewが提供されます。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);
ただし、別の関数を作成したい場合は、このViewlistview変数がありません。onclicklistenerのすぐ外で同じことができるようにするにはどうすればよいですか?ありがとう
ここで編集するのは私のリストビューとアダプターです
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;
}
}