2017-12-31 476 views
-1

안녕하세요, 저는 안드로이드에서 begineer입니다, 내 조각 코드를 활동 코드로 변환하려고하는 중입니다. (버튼 클릭 후이 작업을 시작하고 싶습니다)하지만 이 일활동 코드

public class HistoryFragment extends Fragment implements MainActivity.FragmentRefresh { 

    ImageView ivSettings; 
    private FragmentActivity mContext; 
    private RecyclerView rvInsta; 

    //DB 
    private DBController dbcon; 
    private ImageRecyclerAdaptor imageRecyclerAdaptor; 

    public static HistoryFragment newInstance() { 
     //Bundle args = new Bundle(); 
     //args.putString(ARG_PAGE, title); 
     HistoryFragment fragment = new HistoryFragment(); 
     //fragment.setRetainInstance(true); 
     //fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Log.i("Tag1","MoviesFrag"); 
    } 

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

     View rootView = inflater.inflate(R.layout.fragment_history, container, false); 
     mContext =getActivity(); 
     //DB 
     dbcon = new DBController(mContext); 

     rvInsta= (RecyclerView) rootView.findViewById(R.id.rvInstaImages); 
     imageRecyclerAdaptor = new ImageRecyclerAdaptor(mContext); 
     rvInsta.setAdapter(imageRecyclerAdaptor); 
     rvInsta.setLayoutManager(new LinearLayoutManager(mContext)); 

     rvInsta.setHasFixedSize(true); 
     rvInsta.setItemViewCacheSize(20); 
     rvInsta.setDrawingCacheEnabled(true); 
     rvInsta.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
     //rvInsta.s/ 

     imageRecyclerAdaptor.notifyDataSetChanged(); 
     return rootView; 
    } 

    @Override public void refresh() { 
     if (imageRecyclerAdaptor!=null) { 
      imageRecyclerAdaptor.onRefreshh(); 
     } 
    } 
} 

답변

0
public class MainActivity extends AppCompatActivity implements FragmentRefresh{ 
ImageView ivSettings; 
private RecyclerView rvInsta; 

//DB 
private DBController dbcon; 
private ImageRecyclerAdaptor imageRecyclerAdaptor; 

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

    dbcon = new DBController(this); 

    rvInsta= (RecyclerView) findViewById(R.id.rvInstaImages); 
    imageRecyclerAdaptor = new ImageRecyclerAdaptor(this); 
    rvInsta.setLayoutManager(new LinearLayoutManager(this)); 
    rvInsta.setAdapter(imageRecyclerAdaptor); 


    rvInsta.setHasFixedSize(true); 
    rvInsta.setItemViewCacheSize(20); 
    rvInsta.setDrawingCacheEnabled(true); 
    rvInsta.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
    imageRecyclerAdaptor.notifyDataSetChanged(); 

} 

@Override public void refresh() { 
    if (imageRecyclerAdaptor!= null) { 
     imageRecyclerAdaptor.onRefreshh(); 
    } 
} 

}

+0

thnk의 형제 : 그래서 나에게 여기

도와주세요 그렇게하는 방법을 모른다 나의 조각이다 –