Skip to content

Commit

Permalink
支持了子view为普通的view
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Jul 17, 2019
1 parent 1476808 commit 257adfe
Show file tree
Hide file tree
Showing 27 changed files with 486 additions and 359 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "4.1.2"
versionName "4.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -28,4 +28,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
implementation project(':ncalendar')
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
Binary file added app/general.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
android:name=".activity.TestViewPagerActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.TestGeneralActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
TextView tvVersion = (TextView) findViewById(R.id.tv_version);
tvVersion.setText("版本:" + Utils.getCurrentVersion(this));


}


Expand Down Expand Up @@ -99,6 +100,9 @@ public void viewpager(View view) {
startActivity(new Intent(this, TestViewPagerActivity.class));
}

public void general(View view) {
startActivity(new Intent(this, TestGeneralActivity.class));
}


private Intent getNewIntent(Class<? extends BaseActivity> clazz, SelectedModel selectedModel, String title) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.necer.ncalendar.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.necer.ncalendar.R;

public class TestGeneralActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_general);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.necer.listener.OnCalendarChangedListener;
import com.necer.listener.OnCalendarMultipleChangedListener;
import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.AAAdapter;
import com.necer.ncalendar.adapter.RecyclerViewAdapter;

import org.joda.time.LocalDate;

Expand Down Expand Up @@ -45,8 +45,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
RecyclerView recyclerView = findViewById(R.id.recyclerView);

recyclerView.setLayoutManager(new LinearLayoutManager(this));
AAAdapter aaAdapter = new AAAdapter(this);
recyclerView.setAdapter(aaAdapter);
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this);
recyclerView.setAdapter(recyclerViewAdapter);


miui9Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,49 @@

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.ViewPagerAdapter;
import com.necer.ncalendar.fragment.Fragment1;
import com.necer.ncalendar.fragment.Fragment2;
import com.necer.ncalendar.fragment.Fragment3;

import java.util.ArrayList;
import java.util.List;

public class TestViewPagerActivity extends AppCompatActivity {


private ViewPager viewPager;
private TabLayout tabLayout;


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager);

viewPager = findViewById(R.id.view_pager);
viewPager.setPageMargin(100);
viewPager.setAdapter(new ViewPagerAdapter(this));
tabLayout = findViewById(R.id.tl_tabs);


List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
fragments.add(new Fragment1());
fragments.add(new Fragment2());
fragments.add(new Fragment3());
titles.add("今天");
titles.add("当月");
titles.add("今年");

ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments, titles);

viewPager.setAdapter(viewPagerAdapter);
tabLayout.setupWithViewPager(viewPager);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.necer.calendar.Miui9Calendar;
import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.AAAdapter;
import com.necer.ncalendar.adapter.RecyclerViewAdapter;


/**
Expand All @@ -35,8 +35,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {


recyclerView.setLayoutManager(new LinearLayoutManager(this));
AAAdapter aaAdapter = new AAAdapter(this);
recyclerView.setAdapter(aaAdapter);
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this);
recyclerView.setAdapter(recyclerViewAdapter);

refresh_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@
* Created by necer on 2017/6/7.
*/

public class AAAdapter extends RecyclerView.Adapter<AAAdapter.MyViewHolder> {
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context context;

public AAAdapter(Context context) {
public RecyclerViewAdapter(Context context) {
this.context = context;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_, parent,false));
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_, parent, false));
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
TextView textView = holder.textView;
textView.setText("-----"+position);


textView.setText("RecyclerView ----- " + position);
}

@Override
Expand All @@ -42,6 +40,7 @@ public int getItemCount() {

class MyViewHolder extends RecyclerView.ViewHolder {
TextView textView;

public MyViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.tv_);
Expand Down
48 changes: 17 additions & 31 deletions app/src/main/java/com/necer/ncalendar/adapter/ViewPagerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
package com.necer.ncalendar.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.necer.ncalendar.R;
import java.util.List;

public class ViewPagerAdapter extends PagerAdapter {
public class ViewPagerAdapter extends FragmentPagerAdapter {


private Context mContext;
private List<Fragment> fragmentList;
private List<String> titleList;

public ViewPagerAdapter(Context context) {
this.mContext = context;
public ViewPagerAdapter(FragmentManager fm, List<Fragment> fragmentList, List<String> titleList) {
super(fm);
this.fragmentList = fragmentList;
this.titleList = titleList;
}


@Override
public int getCount() {
return 3;
public Fragment getItem(int position) {
return fragmentList.get(position);
}

@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}


@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
public int getCount() {
return fragmentList.size();
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = View.inflate(mContext, R.layout.item_view_pager, null);

TextView textView = view.findViewById(R.id.tv);
textView.setText(view + "");
container.addView(view);
return view;
public CharSequence getPageTitle(int position) {
return titleList.get(position);
}

}
41 changes: 41 additions & 0 deletions app/src/main/java/com/necer/ncalendar/fragment/Fragment1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.necer.ncalendar.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.RecyclerViewAdapter;

public class Fragment1 extends Fragment {


private RecyclerView recyclerView;


@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment1, container, false);
recyclerView = view.findViewById(R.id.recyclerView);

return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(getContext());
recyclerView.setAdapter(recyclerViewAdapter);

}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/necer/ncalendar/fragment/Fragment2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.necer.ncalendar.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.necer.ncalendar.R;

public class Fragment2 extends Fragment {


@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment2, container, false);
}
}
42 changes: 42 additions & 0 deletions app/src/main/java/com/necer/ncalendar/fragment/Fragment3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.necer.ncalendar.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.necer.ncalendar.R;
import com.necer.ncalendar.adapter.RecyclerViewAdapter;

public class Fragment3 extends Fragment {

private RecyclerView recyclerView;
private TextView tv_no_data;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment3, container, false);
recyclerView = view.findViewById(R.id.recyclerView);
tv_no_data = view.findViewById(R.id.tv_no_data);
return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(getContext());
recyclerView.setAdapter(recyclerViewAdapter);
recyclerView.setVisibility(View.GONE);
tv_no_data.setVisibility(View.VISIBLE);
}
}
11 changes: 0 additions & 11 deletions app/src/main/res/layout/ac_test.xml

This file was deleted.

Loading

0 comments on commit 257adfe

Please sign in to comment.