如何在listview的同一行内点击另一个图像视图时显示图像视图

时间:2016-03-30 09:08:19

标签: android listview baseadapter getview

我试图在同一行上的另一个图像视图被点击时使图像视图可见。有两个主要的图像视图是可见的,两个图像视图最初是不可见的,我需要在点击可见的图像视图时使各个图像视图可见。 / p>

public class MatchListAdapter extends BaseAdapter {

public static final String TAG = ".MatchListAdapter";
MatchStatListAdapter matchStatListAdapter;
public List<RowItem> _data;
private ArrayList<RowItem> users;
RowItem data;
private ArrayList<RowItem> arraylist;
Context _c;
ViewHolder v;
public Typeface tf;
View view_main;
ImageLoader imageLoader;
ViewHolder holder;
public static Integer[] mThumbIds = {R.drawable.delhi,
        R.drawable.gujrat, R.drawable.punjab, R.drawable.kolkata, R.drawable.mumbai, R.drawable.pune,
        R.drawable.banglore, R.drawable.hydrabad};

public static Integer[] arrow_images = {R.drawable.arrow_bg};
int check;
private final boolean[] selectedstates;

public MatchListAdapter(List<RowItem> selectUsers, Context context) {

    _c = context;
    _data = selectUsers;
    this.arraylist = new ArrayList<RowItem>();
    this.arraylist.addAll(_data);
    tf = Typeface.createFromAsset(context.getAssets(), UriUtility.FONTPATH_dark);
    imageLoader = new ImageLoader(context);
    selectedstates = new boolean[_data.size()];
}

@Override
public int getCount() {
    return _data.size();
}

@Override
public Object getItem(int i) {
    return _data.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View getView(final int i, final View convertView, ViewGroup viewGroup) {

    view_main = convertView;
    if (view_main == null) {
        LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view_main = li.inflate(R.layout.group_list_detail, null);
        holder = new ViewHolder();
        holder.team_one = (ImageView) view_main.findViewById(R.id.Image_team1);
        holder.team_two = (ImageView) view_main.findViewById(R.id.Image_team2);
        holder.arrow_one = (ImageView) view_main.findViewById(R.id.arrow_two);
        holder.arrow_two = (ImageView) view_main.findViewById(R.id.arrow_two);

        holder.date = (TextView) view_main.findViewById(R.id.Tview1_date);
        holder.place = (TextView) view_main.findViewById(R.id.Tview1_place);
        holder.vs = (TextView) view_main.findViewById(R.id.Tview1_vs);
        holder.stat_one = (TextView) view_main.findViewById(R.id.Tview1_stats);
        holder.stat_two = (TextView) view_main.findViewById(R.id.Tview2_stats);
        view_main.setTag(holder);
        holder.team_one.setTag(i);
        holder.team_two.setTag(i);
    } else {
        holder = (ViewHolder) view_main.getTag();
        Log.e("Inside", "here--------------------------- In view2 data.getTeam_B()" + data.getTeam_B());
    }
    data = (RowItem) _data.get(i);
    holder.team_one.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_A()) - 1]);
    holder.team_two.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_B()) - 1]);
          holder.team_one.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                           holder.arrow_one.setVisibility(View.VISIBLE);



        }
    });

    holder.team_two.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = (Integer) v.getTag();
            Log.e(TAG, "position of image " + position + "position i = " + i);

        }
    });

    holder.date.setTypeface(tf);
    holder.place.setTypeface(tf);
    holder.vs.setTypeface(tf);
    holder.stat_one.setTypeface(tf);
    holder.stat_two.setTypeface(tf);

    holder.date.setText(data.getMatch_date());
    holder.place.setText(data.getVenue_name());
    holder.stat_one.setText(data.getMatch_date());

    return view_main;
}


static class ViewHolder {
    ImageView team_one, arrow_one, arrow_two;
    ImageView team_two;
    TextView date, place, vs;
    TextView stat_one, stat_two;
    ImageLoader imageLoader;
}

1 个答案:

答案 0 :(得分:0)

经过一番努力,感谢你们的回答。我在下面发布我的答案:

公共类MatchListAdapter扩展了BaseAdapter {

public static final String TAG = ".MatchListAdapter";
MatchStatListAdapter matchStatListAdapter;
public List<RowItem> _data;
private ArrayList<RowItem> users;
RowItem data;
private ArrayList<RowItem> arraylist;
Context _c;
ViewHolder v;
public Typeface tf;
ListView listView;
ImageLoader imageLoader;
int match_id;
public static Integer[] mThumbIds = {R.drawable.arrow_bg,R.drawable.delhi,
        R.drawable.gujrat, R.drawable.punjab, R.drawable.kolkata, R.drawable.mumbai, R.drawable.pune,
        R.drawable.banglore, R.drawable.hydrabad};


int check;
RowItem rowItem;
JSONArray ja;

public MatchListAdapter(List<RowItem> selectUsers, Context context) {

    _c = context;
    _data = selectUsers;
    this.arraylist = new ArrayList<RowItem>();
    this.arraylist.addAll(_data);
    tf = Typeface.createFromAsset(context.getAssets(), UriUtility.FONTPATH_dark);
    imageLoader = new ImageLoader(context);

}

@Override
public int getCount() {
    return _data.size();
}

@Override
public Object getItem(int i) {
    return _data.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View getView(final int i, View convertView, ViewGroup viewGroup) {
    View view = convertView;
    Log.e(TAG, "starting = = 1111111111 position "+ i );
    //if (convertView == null) {
        LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = li.inflate(R.layout.group_list_detail, null);
       team_one = (ImageView) view.findViewById(R.id.Image_team1);
        team_two = (ImageView) view.findViewById(R.id.Image_team2);
        r1 = (RelativeLayout) view.findViewById(R.id.relative_one);
        r2 = (RelativeLayout) view.findViewById(R.id.relative_two);
        date = (TextView) view.findViewById(R.id.Tview1_date);
        place = (TextView) view.findViewById(R.id.Tview1_place);
        vs = (TextView) view.findViewById(R.id.Tview1_vs);
        stat_one = (TextView) view.findViewById(R.id.Tview1_stats);
        stat_two = (TextView) view.findViewById(R.id.Tview2_stats);
        arrow_one = (ImageView) view.findViewById(R.id.arrow_one);
        arrow_two = (ImageView) view.findViewById(R.id.arrow_two);

    //}
    data = (RowItem) _data.get(i);
    team_one.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_A())]);
    team_two.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_B())]);



    date.setText(data.getMatch_date());
    place.setText(data.getVenue_name());
    stat_one.setText(data.getComments());
    boolean one =  data.getCheckedBox();
    boolean two =  data.getCheckedBoxtwo();
    if(one){

        arrow_one.setVisibility(View.VISIBLE);

    }
    if (two){

        arrow_two.setVisibility(View.VISIBLE);
    }



    r1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            data = (RowItem) _data.get(i);


            ImageView arrow_one = (ImageView) v.findViewById(R.id.arrow_one);
            if (data.getCheckedBox() == false) {


                arrow_one.setVisibility(View.VISIBLE);
                data.setCheckedBox(true);
            } else {

                arrow_one.setVisibility(View.INVISIBLE);
                data.setCheckedBox(false);
            }
        }
    });

    r2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ImageView arrow_two = (ImageView) v.findViewById(R.id.arrow_two);
            if (data.getCheckedBoxtwo() == false) {


                arrow_two.setVisibility(View.VISIBLE);
                data.setCheckedBoxtwo(true);
            } else {

                arrow_two.setVisibility(View.INVISIBLE);
                data.setCheckedBoxtwo(false);

            }
        }
    });


    view.setTag(data);
    return view;
}

}