【发布时间】:2016-03-09 19:16:41
【问题描述】:
我想制作一个应用程序,用音乐显示歌词, 我把歌词放在一个定制的列表视图中,下面的布局(行的布局),以及用逗号分隔的文本中歌词的时间, 然后,我想用媒体滚动。
这是我的自定义行布局:
<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 中 Toast Text!但我无法更改 TextView 背景或任何其他操作!为什么以及如何解决这个问题?
【问题讨论】:
标签: android listview view baseadapter