我将展示代码并在解决问题的步骤之后.
我在一个标签片段中有一个recyclerview,它从自定义对象中获取数据集:
mRecyclerView = (RecyclerView) v.findViewById(R.id.recyclerview);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerAdapter = new MyRecyclerAdapter(mMes.getListaItens(), this, getActivity());
mRecyclerView.setAdapter(mRecyclerAdapter);
Run Code Online (Sandbox Code Playgroud)
我在适配器的onBindViewHolder()中设置列表项的longclick行为:
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
ItemMes item = mListaItens.get((position));
holder.descricao.setText(item.getDescrição());
holder.valor.setText(MainActivity.decimalFormatWithCod.format(item.getValor()));
...
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
new MaterialDialog.Builder(mContext)
.title(holder.descricao.getText().toString())
.items(R.array.opcoes_longclick_item)
.itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
switch (which) {
case 0:
mParentFragment.showUpdateItemDialog(position);
return true;
case 1:
mParentFragment.showDeleteItemDialog(position);
return true;
}
return false;
}
})
.show(); …Run Code Online (Sandbox Code Playgroud) 经过一段时间搜索我的NPE的原因后,我注意到尽管FragmentTransaction.remove(Fragment)确实删除了Fragment,但FragmentManager.getFragments()返回的List的大小仍然相同.此屏幕截图显示了删除片段后此方法返回的内容:
https://www.dropbox.com/s/s3bt1p7i71a5kgx/erro%20fm.PNG
该列表有3个片段,为什么大小仍为4?
android android-fragments fragmenttransaction fragmentmanager
我有一个带有列表视图和编辑文本的聊天片段,我想当用户旋转设备时,如果显示了键盘,它仍然显示。但在我的片段上,如果用户从横向旋转到纵向并且键盘打开,它会重新显示为打开。但从纵向到横向,它会关闭旋转。我不知道会发生什么以及如何保存键盘状态来恢复它。提前致谢。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
<com.example.irclient2.adapter.MyEditText
android:id="@+id/chatinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:imeOptions="actionSend|flagNoExtractUi"
android:inputType="textCapSentences" />
<ListView
android:id="@+id/chatlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/chatinput"
android:background="@drawable/fundo_chat"
android:divider="@android:color/transparent"
android:dividerHeight="1.0sp"
android:padding="5dp"
android:scrollingCache="false"
android:smoothScrollbar="true"
android:transcriptMode="normal" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
我使用带有 bitbucket 的 Android Studio。我更改了存储库的名称,现在当我尝试推送时,收到消息Fatal error, repository not found。如何更新我的 Android Studio 项目上的新存储库名称以正确推送?提前致谢。