我想製作一個應用程序,顯示與音樂的歌詞抒情, 我把歌詞放在一個自定義的列表視圖下面的佈局(行的佈局),以及文本中的歌詞時間逗號, 然後,我想用媒體滾動。無法設置視圖背景
這是我行自定義佈局:
<TextView
android:id="@+id/custom_text_arabic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:lineSpacingExtra="15dp"
android:textSize="20sp" />
<TextView
android:id="@+id/custom_text_persian"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:lineSpacingExtra="10dp"
android:textColor="#999999"
android:textSize="12sp" />
</LinearLayout>
,我必須在列表視圖這個自定義行佈局適配器, 我有跟的MediaPlayer播放音樂文件和我的當前位置的聲音,並檢查在一個時間陣列中查找行列表視圖中的位置,然後我在列表視圖中滾動到該行,沿着這一點,我希望行背景變成黑色!
所以,我用這段代碼得到了那一行並改變了它!
// cAdapter is the name of my BaseAdapter and whereIsMe is current child of listview
// that i want to manipulate it
View mVi = cAdapter.getView(whereIsMe-1, null, lv);
TextView persian = (TextView) mVi.findViewById(R.id.custom_text_persian);
// this toast works great!
Toast.makeText(getApplicationContext(),persian.getText(), Toast.LENGTH_LONG).show();
// this part of code is not working!
persian.setBackgroundColor(Color.BLACK);
問題是:
我可以在一個TextView完美吐司的文字!但我無法改變TextView背景或任何其他操作!爲什麼以及如何解決這個問題?
當我使用lv.getChildAt(whereIsMe);然後改變背景,更多的是我的listview的一個孩子改變他們的背景!問題是什麼? –
這是因爲回收,您將不得不在適配器getView方法中設置默認背景。 – Niko
你能解釋一下嗎?我怎樣才能做到這一點? –