Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Listview 自定义列表视图中的两个按钮一个应不可见_Listview_Visibility - Fatal编程技术网

Listview 自定义列表视图中的两个按钮一个应不可见

Listview 自定义列表视图中的两个按钮一个应不可见,listview,visibility,Listview,Visibility,我有一个小问题,因为回收, 问题是我有一个列表项,其中填充了两个文本视图和两个按钮。 一个按钮始终可见(始终显示文本),但另一个按钮为空,因此也不应显示 我尝试了几件事,尝试调整自定义列表中复选框的实现,但没有成功 public class PokeDexListAdapter extends BaseAdapter { Context ctx; LayoutInflater LInflator; ArrayList<PokeDexListItems> pokeDexList;

我有一个小问题,因为回收, 问题是我有一个列表项,其中填充了两个文本视图和两个按钮。 一个按钮始终可见(始终显示文本),但另一个按钮为空,因此也不应显示

我尝试了几件事,尝试调整自定义列表中复选框的实现,但没有成功

public class PokeDexListAdapter extends BaseAdapter {

Context ctx;
LayoutInflater LInflator;
ArrayList<PokeDexListItems> pokeDexList;

public static final String ROW_ID = "row_id"; // Intent extra key

public PokeDexListAdapter(Context context, ArrayList<PokeDexListItems> list) {
    ctx = context;
    pokeDexList = list;
    LInflator = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

@Override
public Object getItem(int position) {
    return pokeDexList.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    PokeDexListItems pokeDexListItems = pokeDexList.get(position);

    if (convertView == null) {
        convertView = LInflator.inflate(R.layout.nat_dex_list_item, null);
    }

    TextView pokeTv = (TextView) convertView.findViewById(R.id.nameDexTv);
    TextView natDexTv = (TextView) convertView.findViewById(R.id.natDexTv);
    Button type1 = (Button) convertView.findViewById(R.id.type1Btn);
    Button type2 = (Button) convertView.findViewById(R.id.type2Btn);

    ImageView pokeSprite = (ImageView) convertView
            .findViewById(R.id.pokeSpriteIV);

    pokeTv.setText(pokeDexListItems.getpokeName());
    natDexTv.setText(pokeDexListItems.getNatDex());
    type1.setText(pokeDexListItems.getType1());
    type2.setText(pokeDexListItems.getType2());

    AssetManager assetManager = ctx.getAssets();

    try {

        InputStream ims = assetManager.open("pokes/"
                + pokeDexListItems.getImageIndex() + ".gif");

        Drawable d = Drawable.createFromStream(ims, null);

        pokeSprite.setImageDrawable(d);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (type1.getText().toString().contains("Bug")) {
        type1.setBackgroundResource(R.drawable.bug_button_border);
    } else if (type1.getText().toString().contains("Dark")) {
        type1.setBackgroundResource(R.drawable.dark_button_border);
    } else if (type1.getText().toString().contains("Dragon")) {
        type1.setBackgroundResource(R.drawable.dragon_button_border);
    } else if (type1.getText().toString().contains("Electric")) {
        type1.setBackgroundResource(R.drawable.electric_button_border);
    } else if (type1.getText().toString().contains("Fairy")) {
        type1.setBackgroundResource(R.drawable.fairy_button_border);
    } else if (type1.getText().toString().contains("Fighting")) {
        type1.setBackgroundResource(R.drawable.fight_button_border);
    } else if (type1.getText().toString().contains("Fire")) {
        type1.setBackgroundResource(R.drawable.fire_button_border);
    } else if (type1.getText().toString().contains("Flying")) {
        type1.setBackgroundResource(R.drawable.flying_button_border);
    } else if (type1.getText().toString().contains("Ghost")) {
        type1.setBackgroundResource(R.drawable.ghost_button_border);
    } else if (type1.getText().toString().contains("Grass")) {
        type1.setBackgroundResource(R.drawable.grass_button_border);
    } else if (type1.getText().toString().contains("Ground")) {
        type1.setBackgroundResource(R.drawable.ground_button_border);
    } else if (type1.getText().toString().contains("Ice")) {
        type1.setBackgroundResource(R.drawable.ice_button_border);
    } else if (type1.getText().toString().contains("Normal")) {
        type1.setBackgroundResource(R.drawable.normal_button_border);
    } else if (type1.getText().toString().contains("Poison")) {
        type1.setBackgroundResource(R.drawable.poison_button_border);
    } else if (type1.getText().toString().contains("Psychic")) {
        type1.setBackgroundResource(R.drawable.psychic_button_border);
    } else if (type1.getText().toString().contains("Rock")) {
        type1.setBackgroundResource(R.drawable.rock_button_border);
    } else if (type1.getText().toString().contains("Steel")) {
        type1.setBackgroundResource(R.drawable.steel_button_border);
    } else if (type1.getText().toString().contains("Water")) {
        type1.setBackgroundResource(R.drawable.water_button_border);
    }

    if (type2.getText().toString().contains("Bug")) {
        type2.setBackgroundResource(R.drawable.bug_button_border);
    } else if (type2.getText().toString().contains("Dark")) {
        type2.setBackgroundResource(R.drawable.dark_button_border);
    } else if (type2.getText().toString().contains("Dragon")) {
        type2.setBackgroundResource(R.drawable.dragon_button_border);
    } else if (type2.getText().toString().contains("Electric")) {
        type2.setBackgroundResource(R.drawable.electric_button_border);
    } else if (type2.getText().toString().contains("Fairy")) {
        type2.setBackgroundResource(R.drawable.fairy_button_border);
    } else if (type2.getText().toString().contains("Fighting")) {
        type2.setBackgroundResource(R.drawable.fight_button_border);
    } else if (type2.getText().toString().contains("Fire")) {
        type2.setBackgroundResource(R.drawable.fire_button_border);
    } else if (type2.getText().toString().contains("Flying")) {
        type2.setBackgroundResource(R.drawable.flying_button_border);
    } else if (type2.getText().toString().contains("Ghost")) {
        type2.setBackgroundResource(R.drawable.ghost_button_border);
    } else if (type2.getText().toString().contains("Grass")) {
        type2.setBackgroundResource(R.drawable.grass_button_border);
    } else if (type2.getText().toString().contains("Ground")) {
        type2.setBackgroundResource(R.drawable.ground_button_border);
    } else if (type2.getText().toString().contains("Ice")) {
        type2.setBackgroundResource(R.drawable.ice_button_border);
    } else if (type2.getText().toString().contains("Normal")) {
        type2.setBackgroundResource(R.drawable.normal_button_border);
    } else if (type2.getText().toString().contains("Poison")) {
        type2.setBackgroundResource(R.drawable.poison_button_border);
    } else if (type2.getText().toString().contains("Psychic")) {
        type2.setBackgroundResource(R.drawable.psychic_button_border);
    } else if (type2.getText().toString().contains("Rock")) {
        type2.setBackgroundResource(R.drawable.rock_button_border);
    } else if (type2.getText().toString().contains("Steel")) {
        type2.setBackgroundResource(R.drawable.steel_button_border);
    } else if (type2.getText().toString().contains("Water")) {
        type2.setBackgroundResource(R.drawable.water_button_border);
    } else {

        type2.setVisibility(View.GONE);

    }

    final int tag = pokeDexListItems.getRowIdTag();
    pokeTv.setTag(tag);

    convertView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                Intent viewPoke = new Intent(ctx, PokedexEntry.class);

                // pass the selected contact's row ID as an extra with the
                // Intent
                viewPoke.putExtra(ROW_ID, getItemId(tag));

                ctx.startActivity(viewPoke); // start the ViewBook Activity
            } catch (Exception e) {
                Toast.makeText(ctx, "This entry does not exist anymore!!",
                        Toast.LENGTH_SHORT).show();
            }

        }
    });
    return convertView;
}

}
公共类PokedXListAdapter扩展了BaseAdapter{
上下文ctx;
拉平机;
ArrayList pokeDexList;
公共静态最终字符串ROW\u ID=“ROW\u ID”;//意图额外键
public PokeDexListAdapter(上下文上下文、ArrayList列表){
ctx=上下文;
pokedxlist=列表;
LInflator=(LayoutInflater)上下文
.getSystemService(上下文布局\充气机\服务);
}
@凌驾
public int getCount(){
返回pokedxlist.size();
}
@凌驾
公共对象getItem(int位置){
返回pokedxlist.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
pokedxlistitems pokedxlistitems=pokedxlist.get(位置);
if(convertView==null){
convertView=LInflator.充气(R.layout.nat索引列表项,空);
}
TextView pokeTv=(TextView)convertView.findViewById(R.id.nameDexTv);
TextView-natDexTv=(TextView)convertView.findViewById(R.id.natDexTv);
按钮类型1=(按钮)convertView.findViewById(R.id.type1Btn);
按钮类型2=(按钮)convertView.findViewById(R.id.type2Btn);
ImageView pokeSprite=(ImageView)convertView
.findviewbyd(R.id.pokeSpriteIV);
setText(pokeDexListItems.getpokeName());
setText(pokeDexListItems.getNatDex());
type1.setText(pokeDexListItems.getType1());
type2.setText(pokeDexListItems.getType2());
AssetManager AssetManager=ctx.getAssets();
试一试{
InputStream ims=assetManager.open(“pokes/”
+getImageIndex()+“.gif”);
Drawable d=Drawable.createFromStream(ims,null);
pokeSprite.setImageDrawable(d);
}捕获(IOE异常){
e、 printStackTrace();
}
if(type1.getText().toString()包含(“Bug”)){
类型1.setBackgroundResource(R.drawable.bug_按钮_边框);
}else if(type1.getText().toString()包含(“暗”)){
类型1.收进背景资源(R.可拉深.深色按钮\边框);
}else if(type1.getText().toString()包含(“Dragon”)){
类型1.setBackgroundResource(R.可绘制的龙按钮边框);
}else if(type1.getText().toString()包含(“电气”)){
类型1.立根地面资源(R.可拉拔。电动按钮\U边框);
}else if(type1.getText().toString()包含(“仙女”)){
类型1.setBackgroundResource(R.drawable.fairy_按钮_边框);
}else if(type1.getText().toString()包含(“战斗”)){
类型1.挫折背景资源(R.可绘制。战斗按钮\边界);
}else if(type1.getText().toString().contains(“Fire”)){
类型1.设置背景资源(R.可绘制。消防按钮\U边框);
}else if(type1.getText().toString()包含(“飞行”)){
类型1.setBackgroundResource(R.可绘制.飞行按钮\边框);
}else if(type1.getText().toString()包含(“重影”)){
类型1.setBackgroundResource(R.drawable.ghost_按钮_边框);
}else if(type1.getText().toString()包含(“草”)){
类型1.收穗地资源(R.可绘制、草地按钮\边界);
}else if(type1.getText().toString()包含(“地面”)){
类型1.收进地面资源(R.可绘制地面按钮边界);
}else if(type1.getText().toString()包含(“Ice”)){
类型1.setBackgroundResource(R.可绘制的ice_按钮_边框);
}else if(type1.getText().toString()包含(“正常”)){
类型1.setBackgroundResource(R.可绘制.正常按钮\U边框);
}如果(type1.getText().toString()包含(“毒药”)){
类型1.setBackgroundResource(R.drawable.poison_按钮_边框);
}else if(type1.getText().toString()包含(“心灵”)){
类型1.setBackgroundResource(R.drawable.Psycholic_按钮_边框);
}else if(type1.getText().toString()包含(“Rock”)){
类型1.立根资源(R.可拉深、岩石按钮和边界);
}else if(type1.getText().toString()包含(“钢”)){
类型1.立根资源(R.可拉深钢制按钮\边框);
}else if(type1.getText().toString()包含(“水”)){
类型1.收穗地资源(R.可提取的水按钮\边界);
}
if(type2.getText().toString()包含(“Bug”)){
类型2.setBackgroundResource(R.drawable.bug_按钮_边框);
}else if(type2.getText().toString()包含(“暗”)){
类型2.收穗地资源(R.可拉深.深色按钮\U边框);
}else if(type2.getText().toString()包含(“Dragon”)){
类型2.setBackgroundResource(R.drawable.dragon_按钮_边框);
}else if(type2.getText().toString()包含(“电气”)){
类型2.立根地面资源(R.可拉拔、电动按钮\U边框);
}else if(type2.getText().toString()包含(“仙女”)){
类型2.setBackgroundResource(R.drawable.fairy_按钮_边框);
}else if(type2.getText().toString()包含(“战斗”)){
类型2.挫折背景资源(R.可绘制。战斗按钮\边界);
}else if(type2.getText().toString().contains(“Fire”)){
类型2.设置背景资源(R.可绘制、防火按钮\U边框);
}else if(type2.getText().toString()包含(“飞行”)){
类型2.setBackgroundResource(R.可绘制.飞行按钮\U边框);
}else if(type2.getText().toString()包含(“重影”)){
类型2.setBackgroundResource(R.可绘制.幻影按钮\U边框);
}else if(type2.getText().toString()包含(“草”)){
类型2.收穗地资源(R.可绘制.草地按钮\边界);
}else if(type2.getText().toString()包含
public class PokeDexListAdapter extends BaseAdapter {

Context ctx;
LayoutInflater LInflator;
ArrayList<PokeDexListItems> pokeDexList;

public static final String ROW_ID = "row_id"; // Intent extra key

public PokeDexListAdapter(Context context, ArrayList<PokeDexListItems> list) {
    ctx = context;
    pokeDexList = list;
    LInflator = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

@Override
public Object getItem(int position) {
    return pokeDexList.get(position);
}

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

private class ViewHolder {
    ImageView pokeSprite;
    TextView pokeTv;
    TextView natDexTv;
    Button type1;
    Button type2;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    PokeDexListItems pokeDexListItems = pokeDexList.get(position);

    if (convertView == null) {
        convertView = LInflator.inflate(R.layout.nat_dex_list_item, null);
        holder = new ViewHolder();
        holder.pokeTv = (TextView) convertView.findViewById(R.id.nameDexTv);
        holder.natDexTv = (TextView) convertView
                .findViewById(R.id.natDexTv);
        holder.type1 = (Button) convertView.findViewById(R.id.type1Btn);
        holder.type2 = (Button) convertView.findViewById(R.id.type2Btn);

        holder.pokeSprite = (ImageView) convertView
                .findViewById(R.id.pokeSpriteIV);
        convertView.setTag(holder);

    } else
        holder = (ViewHolder) convertView.getTag();

    holder.pokeTv.setText(pokeDexListItems.getpokeName());
    holder.natDexTv.setText(pokeDexListItems.getNatDex());
    holder.type1.setText(pokeDexListItems.getType1());
    holder.type2.setText(pokeDexListItems.getType2());

    AssetManager assetManager = ctx.getAssets();

    try {

        InputStream ims = assetManager.open("pokes/"
                + pokeDexListItems.getImageIndex() + ".gif");

        Drawable d = Drawable.createFromStream(ims, null);

        holder.pokeSprite.setImageDrawable(d);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (holder.type1.getText().toString().contains("Bug")) {
        holder.type1.setBackgroundResource(R.drawable.bug_button_border);
    } else if (holder.type1.getText().toString().contains("Dark")) {
        holder.type1.setBackgroundResource(R.drawable.dark_button_border);
    } else if (holder.type1.getText().toString().contains("Dragon")) {
        holder.type1.setBackgroundResource(R.drawable.dragon_button_border);
    } else if (holder.type1.getText().toString().contains("Electric")) {
        holder.type1
                .setBackgroundResource(R.drawable.electric_button_border);
    } else if (holder.type1.getText().toString().contains("Fairy")) {
        holder.type1.setBackgroundResource(R.drawable.fairy_button_border);
    } else if (holder.type1.getText().toString().contains("Fight")) {
        holder.type1.setBackgroundResource(R.drawable.fight_button_border);
    } else if (holder.type1.getText().toString().contains("Fire")) {
        holder.type1.setBackgroundResource(R.drawable.fire_button_border);
    } else if (holder.type1.getText().toString().contains("Flying")) {
        holder.type1.setBackgroundResource(R.drawable.flying_button_border);
    } else if (holder.type1.getText().toString().contains("Ghost")) {
        holder.type1.setBackgroundResource(R.drawable.ghost_button_border);
    } else if (holder.type1.getText().toString().contains("Grass")) {
        holder.type1.setBackgroundResource(R.drawable.grass_button_border);
    } else if (holder.type1.getText().toString().contains("Ground")) {
        holder.type1.setBackgroundResource(R.drawable.ground_button_border);
    } else if (holder.type1.getText().toString().contains("Ice")) {
        holder.type1.setBackgroundResource(R.drawable.ice_button_border);
    } else if (holder.type1.getText().toString().contains("Normal")) {
        holder.type1.setBackgroundResource(R.drawable.normal_button_border);
    } else if (holder.type1.getText().toString().contains("Poison")) {
        holder.type1.setBackgroundResource(R.drawable.poison_button_border);
    } else if (holder.type1.getText().toString().contains("Psychic")) {
        holder.type1
                .setBackgroundResource(R.drawable.psychic_button_border);
    } else if (holder.type1.getText().toString().contains("Rock")) {
        holder.type1.setBackgroundResource(R.drawable.rock_button_border);
    } else if (holder.type1.getText().toString().contains("Steel")) {
        holder.type1.setBackgroundResource(R.drawable.steel_button_border);
    } else if (holder.type1.getText().toString().contains("Water")) {
        holder.type1.setBackgroundResource(R.drawable.water_button_border);
    }

    if (holder.type2.getText().toString().contains("Bug")) {
        holder.type2.setBackgroundResource(R.drawable.bug_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Dark")) {
        holder.type2.setBackgroundResource(R.drawable.dark_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Dragon")) {
        holder.type2.setBackgroundResource(R.drawable.dragon_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Electric")) {
        holder.type2
                .setBackgroundResource(R.drawable.electric_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Fairy")) {
        holder.type2.setBackgroundResource(R.drawable.fairy_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Fight")) {
        holder.type2.setBackgroundResource(R.drawable.fight_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Fire")) {
        holder.type2.setBackgroundResource(R.drawable.fire_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Flying")) {
        holder.type2.setBackgroundResource(R.drawable.flying_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Ghost")) {
        holder.type2.setBackgroundResource(R.drawable.ghost_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Grass")) {
        holder.type2.setBackgroundResource(R.drawable.grass_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Ground")) {
        holder.type2.setBackgroundResource(R.drawable.ground_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Ice")) {
        holder.type2.setBackgroundResource(R.drawable.ice_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Normal")) {
        holder.type2.setBackgroundResource(R.drawable.normal_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Poison")) {
        holder.type2.setBackgroundResource(R.drawable.poison_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Psychic")) {
        holder.type2
                .setBackgroundResource(R.drawable.psychic_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Rock")) {
        holder.type2.setBackgroundResource(R.drawable.rock_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Steel")) {
        holder.type2.setBackgroundResource(R.drawable.steel_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else if (holder.type2.getText().toString().contains("Water")) {
        holder.type2.setBackgroundResource(R.drawable.water_button_border);
        holder.type2.setVisibility(View.VISIBLE);

    } else {
        holder.type2.setVisibility(View.INVISIBLE);
    }

    final int tag = pokeDexListItems.getRowIdTag();
    holder.pokeTv.setTag(tag);

    convertView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                Intent viewPoke = new Intent(ctx, PokedexEntry.class);

                // pass the selected contact's row ID as an extra with the
                // Intent
                viewPoke.putExtra(ROW_ID, getItemId(tag));

                ctx.startActivity(viewPoke); // start the ViewBook Activity
            } catch (Exception e) {
                Toast.makeText(ctx, "This entry does not exist anymore!!",
                        Toast.LENGTH_SHORT).show();
            }

        }
    });
    return convertView;
}

}