我正在使用 Exoplayer 在播放列表中播放视频。我想在当前视频结束时自动播放下一个视频。为此,我EventListener在播放器中添加了一个。这是一个片段:
private val videoPlayerListener = object: Player.EventListener {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
when(playbackState) {
Player.STATE_IDLE -> showLoadingView()
Player.STATE_READY -> hideLoadingView()
Player.STATE_BUFFERING -> showVideoProgressWheel()
Player.STATE_ENDED -> {
Log.d(TAG, "fired")
playNextVideo()
}
}
}
override fun onPlayerError(error: ExoPlaybackException?) {
// handle error event
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法的问题是我的日志显示Player.STATE_ENDED触发了两次。连锁效应是我的播放列表从
视频 1 -> 视频 3 -> 视频 5 -> 视频 7...
代替
视频 1 -> 视频 2 -> 视频 3 -> 视频 4...
我做了一些研究,我在 Github 上发现了这个问题 …
@Override
public void onBindViewHolder(final mainscreenspecializationadap.MyViewHolder holder, final int positionz) {
this.position = holder.getAdapterPosition();
final specializationpojo album = albumList.get(holder.getAdapterPosition());
holder.txtspecs.setText(album.getSplztnname());
holder.imgspecs.setImageResource(album.getIcon());
holder.linelayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
row_index=positionz;
album.setOpened(!album.isOpened());
notifyDataSetChanged();
}
});
if(positionz==row_index){
holder.imageView.setBackground(mContext.getResources().getDrawable(R.drawable.white_circle_background));
holder.txtspecs.setSelected(true);
if (type==1)
{
onClick.onSelected(row_index,album.isOpened(),album.isClosed());
}
else if(type==2)
{ onClick.onSpecialisationSelected(album.getSplzcode(),album.getCount());
}
}
else
{
holder.txtspecs.setSelected(false);
holder.imageView.setBackground(mContext.getResources().getDrawable(R.drawable.green_background));
}
}
Run Code Online (Sandbox Code Playgroud)
I have a recycler view where I need to select only one item, so on that basis, I have to show a sub list items.
Now …
android listview selecteditem background-color android-recyclerview
我有一个表格,当我附加另一个字段时,我不能在我的其他功能中使用它.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".registerNums").click(function(){
$("#hello").append('<input type="button" value="register" class="inputMems">');
});
$(".inputMems").click(function(){
alert("hi")
});
});
</script>
</head>
<body>
<div>
<form>
<div id="hello"></div>
<input type="button" value="register mems" class="registerNums">
</form>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
看我的inputMems按钮不起作用:http://jsfiddle.net/Yelesee/3uecqLxn/
我想在我的 android 手机上创建一个文本文件并在其中写入一些文本。
当我点击按钮时,它说saved to /data/user/0/com.example.savetotextfile/files/example.txt
但我找不到这些文件夹。
大多数应用程序都在设备存储 > Android > 数据中,但我自己创建的应用程序不在那里。
我错过了许可吗?
我不想写入 SD 卡。
public class MainActivity extends AppCompatActivity {
private static final String FILE_NAME = "example.txt";
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
}
public void save(View v) {
String text = editText.getText().toString();
FileOutputStream fos = null;
try {
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(text.getBytes());
editText.getText().clear();
Toast.makeText(this, "Saved to" + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) { …Run Code Online (Sandbox Code Playgroud) android text-files android-external-storage android-internal-storage
我有一个TextView,我OnClickListener对此放了一个TextView。我使用此操作将自定义视图加载到LinearLayout。
但是,当我单击TextView两次时,自定义视图在上重复LinearLayout。LinearLayout在将新的自定义视图加载到this 之前,我会清除所有自定义视图LinearLaout。
这是我OnClickListener的TextView,
TextView rejectedTitleTextView = (TextView) findViewById(R.id.roster_menu_rejected_title);
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rejectedTitleTextView.setBackgroundColor(getResources().getColor(R.color.acceptedPurpleColour));
newTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
acceptedTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
locationLinearLayout.removeAllViews();
rosterBottomLayout.setVisibility(View.GONE);
Log.d("CHECK_ACTION"," REJECTED_TEXT_VIEW ");
InternetConnectivity internetConnectivity = new InternetConnectivity();
final boolean isConnectedToInternet = internetConnectivity.isConnectedToInternet(context);
if(isConnectedToInternet==true) {
try {
Thread.sleep(1300);
} catch (Exception e) {
e.printStackTrace();
}
getDataFromServer("REJECTED");
}else{
Snackbar.make(mainView, "No Internet Connection", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
}); …Run Code Online (Sandbox Code Playgroud) android textview android-layout android-linearlayout onclicklistener
我正在实现一个导航抽屉活动,其中我在导航抽屉中有一个片段(由回收器视图组成)以动态地将项目添加到导航抽屉。
我已经成功地实现了这个概念,但面临一个小问题,即当我点击片段中的任何项目时导航抽屉不会关闭。这是因为我无法从片段访问 DrawerLayout。
那么如何将单击侦听器从我的片段传递到活动以关闭抽屉布局。
谢谢你。
android android-fragments android-activity android-fragmentactivity android-studio
我有一个由自定义对象组成的列表。我想首先根据字母顺序对列表进行分组,然后根据枚举值对这些组进行排序。让我通过代码向您展示:
我的列表:
val list = listOf(Item("America",Severity.CRITICAL), Item("India", Severity.LOW),Item("Australia", Severity.SEVERE),Item("Indonesia", Severity.CRITICAL), Item("Japan", Severity.SEVERE), Item("Jordan", Severity.CRITICAL))
Run Code Online (Sandbox Code Playgroud)
我的Severity枚举类:
enum class Severity{
CRITICAL, SEVERE, MODERATE, LOW
}
Run Code Online (Sandbox Code Playgroud)
我的预期输出:
val sortedList = listOf(Item("America",Severity.CRITICAL),Item("Australia", Severity.SEVERE),Item("Indonesia", Severity.CRITICAL),Item("India", Severity.LOW), Item("Jordan", Severity.CRITICAL),Item("Japan", Severity.SEVERE))
Run Code Online (Sandbox Code Playgroud)
如您所见,该列表包含按字母顺序排列的所有项目,并按照 Severity 枚举类进行排序。
我的点子:
我打算在列表中创建列表。这些子列表将按字母顺序保存所有项目的组,稍后我将根据Severity枚举值对子列表的项目进行排序。
我怎样才能做到这一点?
我能够实现SKAnnotation在skmaps
现在设置单个注释我只想在skmaps地图android中添加多个注释
所以这里是代码片段..任何帮助将不胜感激....
SKAnnotation annotation1 = new SKAnnotation(10);
// set annotation location
annotation1.setLocation(new SKCoordinate(-122.4200, 37.7765));
// set minimum zoom level at which the annotation should be visible
annotation1.setMininumZoomLevel(5);
// set the annotation's type
annotation1.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_RED);
// render annotation on map
mapView.addAnnotation(annotation1, SKAnimationSettings.ANIMATION_NONE);
Run Code Online (Sandbox Code Playgroud)
我到处寻找,并没有得到任何有用的如何实现这.....
在我的应用程序中,我有一个RecyclerView,其中包含15个静态项目,包括一个TextView和一个CheckBox:
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="82dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:scrollbars="vertical" />
Run Code Online (Sandbox Code Playgroud)
单击该项目时,相应的复选框将设置为选中状态,并将该项目添加到选择列表中。
问题:当我向下滚动并选择一个项目时,再次向上滚动我总是看到另一个复选框已选中。在调试时,我注意到,只有我实际选择的项目已添加到列表中,但是,当在UI中随机检查/“选择”其他项目时,这仍然会带来不良的用户体验。
我怎样才能阻止这种奇怪的行为?
我正在使用视图持有者来管理项目视图:
private inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val checkBox: CheckBox = view.findViewById(R.id.checkbox)
val text: TextView = view.findViewById(R.id.text)
init {
view.setOnClickListener { checkBox.isChecked = !checkBox.isChecked }
checkBox.setOnCheckedChangeListener { _, isChecked ->
val itemText = dataset[adapterPosition]
logger.debug("state change $isChecked for $itemText")
if (isChecked) selectedItems.add(itemText)
else {
if (selectedItems.contains(itemText)) selectedItems.remove(itemText)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的onBindViewHolder()方法包含以下内容:
override fun onBindViewHolder(holder: MyViewHolder?, position: Int) {
val itemText = dataset[position]
holder?.text?.text …Run Code Online (Sandbox Code Playgroud) 您有自定义列表视图与以下代码段.
问题是当我运行代码时应用程序崩溃这是我的代码
class MyAdupter extends ArrayAdapter<String>{
Context context;
String[] title ;
String[] description;
int[] images;
public MyAdupter(Context context, String[] title, String[] description, int[] images) {
super(context, R.layout.my_simple_row,title);
this.context = context;
this.title = title;
this.description = description;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Layoutlnflater inflater = (Layoutlnflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.my_simple_row, parent, false);
ImageView imageView = (ImageView) row.findViewById (R.id.imageViewl);
TextView textTitle = (TextView) row.findViewById (R.id.textViewl);
TextView textDescription = (TextView) row.findViewById(R.id.textView2);
imageView.setImageResource(images[position]);
textTitle.setText(title[position]);
textDescription.setText(description[position]);
return row; …Run Code Online (Sandbox Code Playgroud) android ×9
kotlin ×3
arraylist ×1
checkbox ×1
exoplayer2.x ×1
html ×1
javascript ×1
listview ×1
selecteditem ×1
skmaps ×1
sorting ×1
text-files ×1
textview ×1
video-player ×1