1

根据位置,我需要更改列表视图中文本视图的背景颜色。仅当位置为 1 时,我才需要将背景颜色设为红色,否则不应有任何背景颜色。这是我的getview,对于第一个位置,我将颜色设为红色,但对于其他位置,背景颜色在上下滚动列表视图时会发生变化

@Override
    public View getView(final int position, View convertView,
            ViewGroup parent) {



        // TODO Auto-generated method stub
                if (convertView == null) {
                    convertView = getLayoutInflater().inflate(
                            R.layout.bookmarkslayout, null);
                    holder = new ViewHolder();
                    holder.bookMarkImage = (ImageView) convertView
                            .findViewById(R.id.bookMarkImage);
                    holder.bookMarkTitle = (TextView) convertView
                            .findViewById(R.id.bookMarkTitle);
                    holder.bookMarksLayout = (LinearLayout) convertView
                            .findViewById(R.id.bookMarksLayout);
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder) convertView.getTag();
                }
                if (getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    holder.bookMarksLayout.setOrientation(LinearLayout.VERTICAL);
                } else {
                    holder.bookMarksLayout.setOrientation(LinearLayout.HORIZONTAL);
                }
                holder.bookMarkImage.setBackgroundResource(getResources()
                        .getIdentifier(albumArray[position], "drawable",
                                "com.cognizant.vivid"));
                // holder.bookMarkTitle.setText(albumArray[position]);
                holder.bookMarkTitle.setText(AccountsArray[position]);
                if (AccountsArray[position].equalsIgnoreCase("Add Account")) {
                    holder.bookMarkTitle.setBackgroundColor(Color.RED);
                }else{
                    holder.bookMarkTitle.setBackgroundColor(Color.parseColor("#40808080"));
                }
                holder.bookMarksLayout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        // player.reset();
                        if (position == 0) {
                            player.stop();
                            player.release();
                            player = null;
                            surfaceholder = surfaceView.getHolder();
                            surfaceholder.addCallback(Player.this);
                            surfaceholder
                                    .setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
                            player = new MediaPlayer();
                            player.setDisplay(surfaceholder);
                            player.setScreenOnWhilePlaying(true);
                            try {
                                player.setDataSource(
                                        getApplicationContext(),
                                        Uri.parse("http://brightcove.vo.llnwd.net/e1/uds/pd/1937897674001/1937897674001_1939672863001_Wildlife-TamarinMonkey.mp4"));
    //                          player.setDataSource(
    //                                  getApplicationContext(),
    //                                  Uri.parse("http://mspss.cognizant.com/vivid/videos/intuit/2intuit.mp4"));
                            } catch (IllegalArgumentException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (SecurityException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IllegalStateException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                            player.setOnPreparedListener(Player.this);
                            player.prepareAsync();
                            // player.setOnBufferingUpdateListener(this);
                            player.setOnCompletionListener(Player.this);
                            secondaryBookMarksAdapter adapter = new secondaryBookMarksAdapter();
                            bookMarkListView.setAdapter(adapter);
                            bookMarkListViewLandscape.setAdapter(adapter);
                            // VideoTimerHandler videoTimerHandler = new
                            // VideoTimerHandler();
                            // videoTimerHandler.playVideoTimer();
                            // playVideo("http://brightcove.vo.llnwd.net/e1/uds/pd/1937897674001/1937897674001_1939672863001_Wildlife-TamarinMonkey.mp4");
                        } else {
                            if (position == 1) {
                                player.seekTo(115000);
                                timeline.setProgress(115000);
                                player.seekTo(30000);
                                timeline.setProgress(30000);
                            }
                            if (position == 2) {
                                player.seekTo(140000);
                                timeline.setProgress(140000);
                            }
                            if (position == 3) {
                                player.seekTo(205000);
                                timeline.setProgress(205000);
                            }
                            if (position == 4) {
                                player.seekTo(270000);
                                timeline.setProgress(270000);
                            }
                        }
                    }
                });

                return convertView;
            }
4

1 回答 1

0

如果有匹配项,则将其设置为 RED,否则将其设置为其他内容:

        if (AccountsArray[position].equalsIgnoreCase("Add Account")) {
            holder.bookMarkTitle.setBackgroundColor(Color.RED);
        }else{
            holder.bookMarkTitle.setBackgroundColor(Color.parseColor("#40808080"));
        }

我的猜测是您有多个“添加帐户”匹配项。请尝试在 else 中设置断点。

于 2013-07-14T03:46:15.973 回答