Apache Commons Compress 1.14

라이브러리를 import 해줍니다.

jar파일 다운로드 url


import org.apache.commons.compress.utils.IOUtils;

/**
* 파일 복사
*
* @return exist 복사 성공 여부

*/
public synchronized boolean copyFile(String inFilePath, String outFilePath) {
FileInputStream fis = null;
FileOutputStream fos = null;
File file = null;
boolean exist = false;
try {
fis = new FileInputStream(inFilePath);
fos = new FileOutputStream(outFilePath);
IOUtils.copy(fis, fos);

file = new File(outFilePath);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
// 마지막에 FileInputStream / FileOutputStream을 닫아준다.
if (fis != null) try {
fis.close();
}
catch (IOException e) {
Log.i("파일복사", "fileInput error");
}

if (fos != null)
try {
fos.close();
}
catch (IOException e) {
Log.i("파일복사", "fileOutput error");
}
if (file != null) {                 // 복사한 경로에 File있는지 확인
if (file.exists()) {
exist = true;
}
else {
exist = false;
}
}

}
return exist;
}



728x90
반응형

https://developer.android.com/preview/features/working-with-fonts.html?hl=ko#fonts-in-xml 

해당 페이지에서 번역하여 저 나름대로의 주관적인 의견을 더한 게시물입니다.


Android O에는 XML안에서 font리소스를 사용할 수 있는 새로운 기능이 추가되었습니다.

이제 색다른 글씨체로 안드로이드 앱을 구현할 수 있습니다.(일이 늘어날거 같은 느낌...)

Android O는 시스템 font와 관련된 정보를 검색하고 파일 설명자를 제공하는 메커니즘도 제공합니다.


Font 및 XML

Android O를 사용하면 font파일을 res / font / (요기)  해당 경로에 font를 추가하여 글꼴들을 한데 모아놓을 수 있습니다. 

이 글꼴은 R 파일에서 컴파일되며 Android Studio에서 자동으로 사용할 수 있습니다.

기존에 리소스 R.id 처럼 글꼴을 인식할 수 있습니다.

@font/myfont, or R.font.myfont.

font를 리소스로 추가하려면 Android Studio에서 다음 단계를 수행하십시오.

1. res 폴더를 마우스 오른쪽 버튼으로 클릭하고 새로 만들기> Android 리소스 디렉토리로 이동하십시오. New Resource Directory 창이 나타납니다.

2. 리소스 종류 목록에서 font을 선택한 다음 확인을 누릅니다.

참고: font파일을 넣을 디렉토리의 이름은 무조건 font여야합니다.


font 디렉토리를 만든다.


3. font 디렉토리에 font파일 추가 합니다.

아래 그림처럼 font 디렉토리에 font파일을 넣어 두면 R.font.dancing_scriptR.font.lobster 해당이름으로 font를 불러올 수 있습니다.



4. font파일을 두번 클릭하면 편집기에서 해당 파일의 font를 미리볼 수 있습니다.


XML 레이아웃에서 font를 사용

TextView 객체나 style에서 font를 쉽게 사용할 수 있습니다.

TextView 객체나 style에서 font를 연결하려면 fontFamily 특성을 사용하면 됩니다.

- TextView에 font 추가

<TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:fontFamily="@font/lobster"/>

- Style에 font 추가

<style name="customfontstyle" parent="@android:style/TextAppearance.Small">
   
<item name="android:fontFamily">@font/lobster</item>
</style>

- 코드에서 font 추가

Typeface typeface = getResources().getFont(R.font.myfont);
textView
.setTypeface(typeface);


더욱 자세한 사항은 해당페이지에서 확인 하세요.

https://developer.android.com/preview/features/working-with-fonts.html?hl=ko#retrieving-system-fonts

728x90
반응형


public abstract class BaseActivity extends AppCompatActivity {

protected ProgressDialog mProgressDialog = null;

protected abstract Context getContext();

/**
* 프로그래스를 보여준다.
*/
public void showProgressDialog() {
if (mProgressDialog == null) {
if (Build.VERSION_CODES.KITKAT < Build.VERSION.SDK_INT) {

//             R.style.ProgressDialogStyle은 커스텀으로 정의한 스타일임
mProgressDialog = new ProgressDialog(getNowContext(), R.style.ProgressDialogStyle);

} else {
mProgressDialog = new ProgressDialog(getNowContext());
}
mProgressDialog.setMessage(getString(R.string.progress_message));
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
}
mProgressDialog.show();
}

/**
* 프로그래스를 숨긴다.
*/
public void hideProgressDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}

}


R.style.ProgressDialogStyle

<style name="ProgressDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:layout_centerVertical">true</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="colorAccent">@color/colorPrimary</item>
</style>


사용 할 때

private class DownloadTask extends AsyncTask{


@Override
protected void onPreExecute() {
showProgressDialog(); // 작업 시작


//작업 준비 코드 작성
super.onPreExecute();
}


@Override
protected Object doInBackground(Object[] params) {
//작업 중
return null;
}

@Override
protected void onPostExecute(Object o) {
//작업 끝 코드 작성

hideProgressDialog(); // 작업 끝
super.onPostExecute(o);
}
}

 이런 느낌으로 사용하시면 됩니다.

728x90
반응형

많은 앱들이 카카오톡 처럼 탭 뷰페이저 형식을 사용합니다.



그래서 간단히 TabLayout + ViewPager + fragment 형식의 앱을 만들어서 공유드립니다.


다음과 같이 만들었는데요 


1. 라이브러리 셋팅


compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'


- AppCompatActivity클래스는 appcompatV7 라이브러리에 포함되어 있습니다.

- ViewPager클래스는 supportV4 라이브러리에 포함되어 있습니다.

- TabLayout은 design 라이브러리에 포함되어 있습니다.

2. 소스코드

MainActivity.java

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

import pe.sk.com.myapplication.R;
import pe.sk.com.myapplication.adapter.MainTabPagerAdapter;
import pe.sk.com.myapplication.data.DummyContent;
import pe.sk.com.myapplication.listener.OnListFragmentInteractionListener;

public class MainActivity extends AppCompatActivity implements OnListFragmentInteractionListener {
private TabLayout mTabLayout = null; // 탭 레이아웃
private ViewPager mViewPager = null; // 뷰 페이저
private MainTabPagerAdapter mPagerAdapter = null; // 탭 어댑터

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabLayout = (TabLayout) findViewById(R.id.main_tab);
mViewPager = (ViewPager) findViewById(R.id.main_viewpager);
mTabLayout.setupWithViewPager(mViewPager);

mPagerAdapter = new MainTabPagerAdapter(getSupportFragmentManager(), this);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {

}

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});
}

@Override
public void onListFragmentInteraction(DummyContent.DummyItem item) {
Toast.makeText(this,item.content,Toast.LENGTH_SHORT).show();
}
}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.TabLayout
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/main_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#ff880033"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#bbdefa"
app:tabSelectedTextColor="#ffffff"
app:tabTextColor="#88ffffff"
/>


<android.support.v4.view.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/main_tab"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

MainTabPagerAdapter.java


import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import pe.sk.com.myapplication.R;
import pe.sk.com.myapplication.fragment.FirstFragment;
import pe.sk.com.myapplication.fragment.TwoFragment;

/**
* Created by P092613 on 2017-03-09.
*/

public class MainTabPagerAdapter extends FragmentStatePagerAdapter {
private final static int TAB_COUNT = 2;     // 탭의 개수


private Context mContext;
private FirstFragment mFirstFragment = null;
private TwoFragment mTwoFragment = null;

private int[] mTabTitle = {R.string.first, R.string.two};

public MainTabPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.mContext = context;
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
mFirstFragment = FirstFragment.newInstance(1);
return mFirstFragment;
default:
mTwoFragment = TwoFragment.newInstance(1);
return mTwoFragment;
}
}

@Override
public CharSequence getPageTitle(int position) {
return mContext.getString(mTabTitle[position]);
}

@Override
public int getCount() {
return TAB_COUNT;
}
}


FirstFragment.java 와 TwoFragment.java 코드는 동일함

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
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 pe.sk.com.myapplication.R;
import pe.sk.com.myapplication.adapter.FirstRecyclerViewAdapter;
import pe.sk.com.myapplication.data.DummyContent;
import pe.sk.com.myapplication.listener.OnListFragmentInteractionListener;

/**
* A fragment representing a list of Items.
* <p/>
* Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
* interface.
*/
public class FirstFragment extends Fragment {

// TODO: Customize parameter argument names
private static final String ARG_COLUMN_COUNT = "column-count";
// TODO: Customize parameters
private int mColumnCount = 1;
private OnListFragmentInteractionListener mListener;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public FirstFragment() {
}

// TODO: Customize parameter initialization
@SuppressWarnings("unused")
public static FirstFragment newInstance(int columnCount) {
FirstFragment fragment = new FirstFragment();
Bundle args = new Bundle();
args.putInt(ARG_COLUMN_COUNT, columnCount);
fragment.setArguments(args);
return fragment;
}

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

if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_first_list, container, false);

// Set the adapter
if (view instanceof RecyclerView) {
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
if (mColumnCount <= 1) {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
}
recyclerView.setAdapter(new FirstRecyclerViewAdapter(DummyContent.ITEMS, mListener));
}
return view;
}


@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}


}


FirstRecyclerViewAdapter.java 와 TwoRecyclerViewAdapter.java 코드는 동일함


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import pe.sk.com.myapplication.R;
import pe.sk.com.myapplication.data.DummyContent.DummyItem;
import pe.sk.com.myapplication.listener.OnListFragmentInteractionListener;

/**
* {@link RecyclerView.Adapter} that can display a {@link DummyItem} and makes a call to the
* specified {@link OnListFragmentInteractionListener}.
* TODO: Replace the implementation with code for your data type.
*/
public class FirstRecyclerViewAdapter extends RecyclerView.Adapter<FirstRecyclerViewAdapter.ViewHolder> {

private final List<DummyItem> mValues;
private final OnListFragmentInteractionListener mListener;

public FirstRecyclerViewAdapter(List<DummyItem> items, OnListFragmentInteractionListener listener) {
mValues = items;
mListener = listener;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_first, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
holder.mIdView.setText(mValues.get(position).id);
holder.mContentView.setText(mValues.get(position).content);

holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onListFragmentInteraction(holder.mItem);
}
}
});
}

@Override
public int getItemCount() {
return mValues.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mIdView;
public final TextView mContentView;
public DummyItem mItem;

public ViewHolder(View view) {
super(view);
mView = view;
mIdView = (TextView) view.findViewById(R.id.id);
mContentView = (TextView) view.findViewById(R.id.content);
}

@Override
public String toString() {
return super.toString() + " '" + mContentView.getText() + "'";
}
}
}


fragment_first_list.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
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"
android:id="@+id/list"
android:name="pe.sk.com.myapplication.fragment.FirstItemFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="pe.sk.com.myapplication.fragment.FirstFragment"
tools:listitem="@layout/fragment_first"/>


fragment_first.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem"/>

<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem"/>
</LinearLayout>


728x90
반응형

뷰페이저를 사용중에 특정 페이지만 툴바메뉴가 보였으면 좋겠다고 하는 미치광이들이 아주 간혹 있습니다.


이런 미치광이들을 상대하는 개발자들을 위해 공유드립니다


                                        


1번1번  2번





우선 findViewById메서드로 Toolbar객체 DrawerLayout객체를 만들어 줍니다.

/**
* 1번 좌측메뉴, 좌측슬라이드 노출되도록 설정
*/
protected void setToolbarVisibleLeftMenu() {
if (mToolbar != null && mDrawerLayout != null) {
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(true);
// 상단 툴바를 이용하여 좌측 메뉴 열기 / 닫기 설정
mActionBarDrawerToggle = new ActionBarDrawerToggle((Activity) getNowContext(), mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
// Drawer Toggle Object Made
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); // Drawer Listener set to the Drawer toggle
mActionBarDrawerToggle.syncState();
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
}

/**
* 2번 좌측메뉴, 좌측슬라이드 노출되지않도록 설정
*/
protected void setToolbarGoneLeftMenu() {
if (mToolbar != null && mDrawerLayout != null) {
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
}


728x90
반응형

안드로이드는 다음과 같이 휠을 날짜나 시간, 숫자만 제공해줍니다.


  





글자(String)가 쓰여진 휠뷰는 안드로이드 자체적으로 제공해 주지 않습니다. 그래서 lib를 써야합니다.

많은  lib들이 있지만 그중에 가장 괜찮고 안정성 있는 lib라고 생각되어 소개합니다.



Github 주소

https://github.com/maarek/android-wheel





Demo


@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


setContentView(R.layout.cities_layout);

String[] locationData= new String[]{"남산", "대구", "부산", "인천", "경주", "안산", "서울", "광주", "충주", "강원"};



WheelView country = (WheelView) findViewById(R.id.country);


  // Cyclic 여부 true일경우 위아래로 값이 생겨서 무제한 스크롤 가능(직접 해보시길 설명을 못하겟음) 

country.setCyclic(false);

country.setCurrentItem(0); // position 설정 혹은 index 설정

country.setVisibleItems(3); // 보여줄 item의 개수(테스트 결과 이 함수는 적용되지 않는다.)

ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this, locationData);

adapter.setTextSize(30); // 글씨 크기

country.setViewAdapter(adapter); //어댑터를 설정한다.

country.addScrollingListener( new OnWheelScrollListener() {

@Override

public void onScrollingStarted(WheelView wheel) {

// 스크롤 시작

scrolling = true;

}

@Override

public void onScrollingFinished(WheelView wheel) {

// 스크롤 끝

scrolling = false;

}

});

}




이슈사항


- 아래 그림의 휠 두개는 서로 연동 됩니다. 예를 들어 지역 휠을 컨트롤 하여 "남산"을 선택 시 층은 11층까지 보이도록 갱신됩니다.

 앞에 설명과 같이 지역 휠을 컨트롤 하여 "부산"을 선택 시 1층만 보이도록 갱신됩니다.

ex)

남산 - 1,2,3,4,5,6,7,8,9,10,11층

대구 - 1,2,3층

부산 - 1층

인천 - 1,2,3,4,5,6층

   .

   .

   .



-휠을 두개 쓸 경우 층 휠을 맨 밑으로 내리고 바로 지역 휠을 스크롤 할 경우 층 휠의 층수가 보이지 않는 이슈가 있습니다.




해결방법

-완벽한 해결 방법은 아니지만 onScrollingStarted콜백이 호출 될때마다 층휠을 setCurrentItem(0);으로 초기화 해주면 해당이슈사항은 해결 됩니다. 

728x90
반응형

액티비티를 호출 할 때


Intent intent = new Intent(MainActivity.this, SubActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_left);



액티비티를 종료할 때


@Override
public void finish() {
super.finish();
if(isChoice){
overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_left);
}else{
overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_right);
}
}

anim 파일들은 해당경로에 넣어주세요


res/anim/여기에 밑에 파일들을 넣어주세요.



anim_slide_in_left.xml

anim_slide_in_right.xml

anim_slide_out_left.xml

anim_slide_out_right.xml


728x90
반응형

먼저 RecyclerView를 만들기 위해서 



앱 build.gradle에 appcompatV7와 recycleview lib를 추가해야합니다.


compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'



MainActivity


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.damoa.testfragment.dummy.DummyContent;

public class MainActivity extends AppCompatActivity {

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

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.test_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new MyItemRecyclerViewAdapter(this,DummyContent.ITEMS));
}

}



MyItemRecyclerViewAdapter


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.damoa.testfragment.dummy.DummyContent.DummyItem;

import java.util.List;


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

private final List<DummyItem> mValues;
private Context mContext = null;

public MyItemRecyclerViewAdapter(Context context, List<DummyItem> items) {
mContext = context;
mValues = items;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_item, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mTitle.setText(mValues.get(position).title);

holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext,"test"+position,Toast.LENGTH_SHORT).show();
}
});
}

@Override
public int getItemCount() {
return mValues.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mTitle;

public ViewHolder(View view) {
super(view);
mView = view;
mTitle = (TextView) view.findViewById(R.id.item_title);
}

}
}



DummyContent


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

/**
* Helper class for providing sample content for user interfaces created by
* Android template wizards.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class DummyContent {

/**
* An array of sample (dummy) items.
*/
public static final List<DummyItem> ITEMS = new ArrayList<DummyItem>();


private static final int COUNT = 25;

static {
// Add some sample items.
for (int i = 1; i <= COUNT; i++) {
addItem(createDummyItem(i));
}
}

private static void addItem(DummyItem item) {
ITEMS.add(item);
}

private static DummyItem createDummyItem(int position) {
return new DummyItem(String.valueOf(position)+"Item "+ position);
}

private static String makeDetails(int position) {
StringBuilder builder = new StringBuilder();
builder.append("Details about Item: ").append(position);
for (int i = 0; i < position; i++) {
builder.append("\nMore details information here.");
}
return builder.toString();
}

/**
* A dummy item representing a piece of content.
*/
public static class DummyItem {
public final String title;

public DummyItem(String id) {
this.title = id;
}
}
}



activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.damoa.testfragment.MainActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/test_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>



recycler_item.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem" />

</LinearLayout>



728x90
반응형

+ Recent posts