1
基於位置,我需要改變列表視圖中的文本視圖的背景顏色。 僅當位置爲1時我需要將背景顏色設置爲紅色,否則不應該有任何背景顏色。 這裏是我getview,對於我得到的顏色爲紅色第一的位置,但對於其他位置,背景顏色變化上滾動列表視圖上下getview的listview中的setbackground問題
@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;
}
這裏是陣列私有String [] AccountsArray = { 「添加帳戶」, 「會計科目表」, \t \t \t 「選擇功能」, 「公司文件位置」, 「QB設立」}; – user2558496
@ user2558496您是否嘗試設置斷點並查看它是否多次達到RED? – Warpzit