1

在我的getView方法中:

    public View getView(int index, View view, ViewGroup parent) {
        if (view == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            view = inflater.inflate(R.layout.linha_historico_layout, parent, false);
    }

    DadosHistorico dadosHistorico = (DadosHistorico) getItem(index);

    TextView tvdata = (TextView) view.findViewById(R.id.tvData);
    tvdata.setText(dadosHistorico.getData());

    TextView ivstatushistorico = (TextView) view.findViewById(R.id.tvStatushistorico);
    ivstatushistorico.setText(dadosHistorico.getStatus());

    TextView tvInternetTitlo = (TextView) view.findViewById(R.id.tvInternetTitulo);
    tvInternetTitlo.setText(dadosHistorico.getInternet());

    TextView tvLigacaoTitulo = (TextView) view.findViewById(R.id.tvLigacaoTitulo);
    tvLigacaoTitulo.setText(dadosHistorico.getLigacao());

    TextView tvInternetDescricao = (TextView) view.findViewById(R.id.tvInternetDescricaoHistorico);
    tvInternetDescricao.setText(dadosHistorico.getInternetDescricao());

    TextView tvLigacaiDescricao = (TextView) view.findViewById(R.id.tvLigacaoDescricaoHistorico);
    tvLigacaiDescricao.setText(dadosHistorico.getLigacaoDescricao());

    TextView tvComentarioHistorico = (TextView)view.findViewById(R.id.tvComentarioHistorico);
    tvComentarioHistorico.setText(dadosHistorico.getComentario());

    final String comentario = tvComentarioHistorico.getText().toString();

    ImageView ivStatusLed = (ImageView) view.findViewById(R.id.ivStatusLe);


    if(ivstatushistorico.getText().equals("1")){
        ivStatusLed.setBackgroundResource(R.drawable.green_led);    
        ivStatusLed.setVisibility(View.VISIBLE);
    }    


    ImageView ibComentarioHistorico = (ImageView)view.findViewById(R.id.ibComentarioHistorico);

    if(comentario.equals("")){
        ibComentarioHistorico.setVisibility(View.INVISIBLE);
     }else{
        ibComentarioHistorico.setVisibility(View.VISIBLE);

     }


    ibComentarioHistorico.setOnClickListener(new OnClickListener() {    
        public void onClick(View v) {
            AlertDialog alertDialog = new AlertDialog.Builder(c).create();
            alertDialog.setTitle("Comentário");
            alertDialog.setMessage(comentario);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });

            alertDialog.show();


        }
    });


    return view;


    }

    public void addDados(String data, String status, String internet, String internetDescricao, String ligacao, String ligacaoDescricao, String comentario) {
        dados.add(new DadosHistorico(data, status, internet, internetDescricao, ligacao, ligacaoDescricao, comentario));

}
}

在此代码中,我更改了列表中的图像视图。我从数据库接收一些数据并更改图像视图。问题是,当我向下滚动列表视图并向后滚动时,图像视图不同,有时是 gream_led,有时是 ibComentarioHistorico 消失。

4

1 回答 1

1

添加else声明:

if(ivstatushistorico.getText().equals("1")){
    ivStatusLed.setBackgroundResource(R.drawable.green_led);    
    ivStatusLed.setVisibility(View.VISIBLE);
}
else {
    ivStatusLed.setBackgroundResource(R.drawable.your_default);    
    ivStatusLed.setVisibility(View.INVISIBLE); // or whatever the default is
}

视图被重用,所以除非你告诉它如果它不等于“1”要做什么,你会看到你描述的行为。

于 2013-07-15T12:40:21.980 回答