小编fek*_*kra的帖子

选项卡之间更改时刷新片段

应用程序打开第一个片段,有2个选项卡我想刷新第二个片段,当我移动到它但我不想刷新第一个片段

主要活动

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

}
private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new Main_Button(), "Main");
    adapter.addFragment(new TwoFragment(), "Main2");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

10
推荐指数
2
解决办法
2万
查看次数

使用图像添加折叠工具栏

我想添加折叠工具栏与图像我尝试了很多代码但我遇到很多问题我想在布局中添加它我使用RecyclerView和导航抽屉

请帮我添加像这样的折叠工具栏

在此输入图像描述

content_r_arabic

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kamal.ahmed.rewaya.R_arabic"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@drawable/bg"
tools:showIn="@layout/app_bar_r_arabic">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adView"
    android:layout_alignParentTop="true"
    android:layout_marginRight="23dp">
</android.support.v7.widget.RecyclerView>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progress_layout"
    android:gravity="center_vertical"
    android:layout_marginTop="270dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true">

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="100dp"
        android:layout_marginBottom="5dp"
        android:layout_weight="1"/>

    <TextView
        android:text="???? ???????"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progress_txt"
        android:textSize="22sp"
        android:textStyle="bold"
        android:textColor="#e873400c"
        android:layout_gravity="center"
        android:layout_marginRight="90dp"
        android:layout_marginBottom="5dp"
        android:layout_weight="1" />

</LinearLayout></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

app_bar_r_arabic

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kamal.ahmed.rewaya.R_arabic"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@drawable/bg"
tools:showIn="@layout/app_bar_r_arabic">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adView"
    android:layout_alignParentTop="true"
    android:layout_marginRight="23dp">
</android.support.v7.widget.RecyclerView>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progress_layout"
    android:gravity="center_vertical" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

5
推荐指数
1
解决办法
4948
查看次数

RecyclerView 搜索过滤器位置错误

我使用 RecyclerView 并对其进行了过滤,但我遇到了问题

在我搜索后,当我按下项目时,我得到了错误的位置,而不是我搜索到的位置,请帮我解决这个问题

RecyclerView 适配器

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

Context context;
List<listitem_gib> getDataAdapter;



public RecyclerViewAdapter(List<listitem_gib> getDataAdapter, Context context){

    super();

    this.getDataAdapter = getDataAdapter;
    this.context = context;

}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_layout, parent, false);

    ViewHolder viewHolder = new ViewHolder(v,context,getDataAdapter);

    return viewHolder;
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {

    listitem_gib getDataAdapter1 =  getDataAdapter.get(position);

    holder.name.setText(getDataAdapter1.getName());
    holder.num.setText(getDataAdapter1.getnum());
    Picasso.with(context).load("http://i-geeky.info/android/image/" + getDataAdapter1.getimg()).into(holder.img1);


}

@Override
public int getItemCount() {

    return getDataAdapter.size();
}

class …
Run Code Online (Sandbox Code Playgroud)

android

4
推荐指数
1
解决办法
5036
查看次数