我在Seekbar上有一个带有选框效果的textview。 这是我的搜索栏听众。
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (mediaPlayer != null && fromUser) {
mediaPlayer.seekTo(progress * 1000);
}
}
});
因此,当我使用搜索栏进行搜索时,上面的文本视图会使用选框文本刷新。所有手机都不会发生这种情况。
以下几行仅为textview编写:
textView.setSelected(true);
textView.setText("aaaaa bbbbbbb ccccccc ddddddddd eeeeeeee ffffffff gggggggg");
这是我的xml的一部分:
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/seekBar"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/tog"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:layout_marginRight="60dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ffffff"
android:id="@+id/songName"
android:text="Song Name"
android:layout_alignTop="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:layout_marginLeft="5dp"
android:layout_marginRight="50dp" />
我不知道为什么在我寻找的时候文本视图会被刷新。我该如何解决这个问题?我寻求帮助!! TIA
编辑:我认为再次提到某些手机出现问题是明智之举。完整代码:
setContentView(R.layout.activity_section_one);
final ListView listView = (ListView)findViewById(R.id.sec1list);
final TextView textView = (TextView)findViewById(R.id.songName);
tduration = (TextView)findViewById(R.id.totalDuration);
telapsed = (TextView)findViewById(R.id.elapsedtime);
seekBar = (SeekBar)findViewById(R.id.seekBar);
tg = (ToggleButton)findViewById(R.id.tog);
textView.setSelected(true);
textView.setFocusable(false);
textView.setText("aaaaa bbbbbbb ccccccc ddddddddd eeeeeeee ffffffff gggggggg");
textView.setText("Tobu bhoy nei maa amra protibad korte jani");
// Check whether we're recreating a previously destroyed instance
Log.d("TAG", "Going to check whether Music is playing");
Log.d("TAG", "Player Status " + mediaPlayer.isPlaying() + " Saved Instatus ");
if(notificationManager!= null){
notificationManager.cancelAll();
}
if(mediaPlayer.isPlaying()){
Log.d("TAG", "Music is playing at time " + mediaPlayer.getCurrentPosition());
handlerTIme();
setNotification();
tg.setChecked(true);
}
tg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mediaPlayer != null && !mediaPlayer.isPlaying() && POSITION!=-1) {
playMedia();
Log.d("TAG", "Played " + mediaPlayer.isPlaying());
} else if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
notificationManager.cancelAll();
tg.setChecked(false);
Log.d("TAG", "Paused " + mediaPlayer.isPlaying());
} else if (POSITION == -1 && !mediaPlayer.isPlaying()) {
tg.setChecked(false);
Log.d("TAG", "POSITION -1");
}
}
});
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (mediaPlayer != null && fromUser) {
mediaPlayer.seekTo(progress * 1000);
}
}
});
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
textView.setText(values[position]);
textView.setSelected(true);
POSITION = position;
tg.setChecked(true);
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
notificationManager.cancelAll();
}
mediaPlayer = MediaPlayer.create(SectionOne.this, songIds[position]);
seekBar.setMax(mediaPlayer.getDuration()/1000);
Log.d("TAG", "Duration" + mediaPlayer.getDuration());
playMedia();
handlerTIme();
}
});
}
private void handlerTIme() {
Log.d("TAG","Inside the handler");
int seconds = (int) (mediaPlayer.getDuration() / 1000) % 60 ;
int minutes = (int) ((mediaPlayer.getDuration() / (1000*60)) % 60);
tduration.setText(Integer.toString(minutes) + ":" + Integer.toString(seconds));
SectionOne.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mediaPlayer != null) {
int mCurrentPosition = mediaPlayer.getCurrentPosition() / 1000;
seekBar.setMax(mediaPlayer.getDuration() / 1000);
seekBar.setProgress(mCurrentPosition);
int seconds = (int) (mediaPlayer.getCurrentPosition() / 1000) % 60;
int minutes = (int) ((mediaPlayer.getCurrentPosition() / (1000 * 60)) % 60);
if (minutes < 10) {
min = "0" + Integer.toString(minutes);
} else {
min = Integer.toString(minutes);
}
if (seconds < 10) {
sec = "0" + Integer.toString(seconds);
} else {
sec = Integer.toString(seconds);
}
telapsed.setText(min + ":" + sec);
}
mHandler.postDelayed(this, 1000);
}
});
}
private void playMedia(){
mediaPlayer.start();
setNotification();
}
public void setNotification(){
String ns = Context.NOTIFICATION_SERVICE;
notificationManager = (NotificationManager) getSystemService(ns);
notification = new Notification(R.drawable.aa1, null, System.currentTimeMillis());
RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.controller);
//the intent that is started when the notification is clicked (works)
Intent notificationIntent = new Intent(this, HomeActivity.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentView = notificationView;
notification.contentIntent = pendingNotificationIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(1, notification);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.eatl.shadhinotamusic.SectionOne"
android:background="#fbfaf5">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:background="@drawable/aa1"
android:id="@+id/sec1head"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:id="@+id/sec1list"
android:layout_marginBottom="80dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<RelativeLayout
android:layout_width="match_parent"
android:background="@drawable/bottomseconegradient"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ffffff"
android:id="@+id/songName"
android:text="Song Name"
android:layout_alignTop="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:layout_marginLeft="5dp"
android:layout_marginRight="50dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/tog"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:id="@+id/relativeLayout">
</RelativeLayout>
<ToggleButton
android:layout_width="50dp"
android:layout_height="50dp"
android:textOff=""
android:textOn=""
android:background="@drawable/toggle"
android:id="@+id/tog"
android:checked="false"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/aa1"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/totalDuration"
android:layout_below="@+id/seekBar"
android:layout_alignRight="@+id/seekBar"
android:layout_alignEnd="@+id/seekBar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/elapsedtime"
android:layout_below="@+id/seekBar"
android:layout_alignLeft="@+id/songName"
android:layout_alignStart="@+id/songName" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/seekBar"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/relativeLayout"
android:layout_alignStart="@+id/relativeLayout"
android:layout_marginRight="60dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Some text will come here regarding the songs and the artists may be and then blablabla but not so long that it screws up the view"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/sec1head"
android:layout_toEndOf="@+id/sec1head"
android:layout_margin="5dp" />
</RelativeLayout>