소스 다운받는곳

https://github.com/tlshenm/SearchToolbarTest


----------------------------------------------------------CODE-------------------------------------------------

 

SearchActivity


 

public class SearchActivity extends AppCompatActivity {

private NoticeRecyclerAdapter mAdapter;
private NoticeContent mNoticeContent;

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

private void initView() {
getIntentDate();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.notice_search_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new NoticeRecyclerAdapter(this, mNoticeContent.getNoticeList()); //new NoticeRecyclerAdapter(Context, 당신의 데이터 리스트)
recyclerView.setAdapter(mAdapter);
}

private void getIntentDate(){
Intent intent = getIntent();
mNoticeContent =(NoticeContent)intent.getExtras().getSerializable(NoticeContent.NOTICE_CONTENT);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) findViewById(R.id.notice_search_view);
searchView.onActionViewExpanded(); //바로 검색 할 수 있도록

if (searchView != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));
searchView.setQueryHint(getString(R.string.notice_search_hint));
queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
Log.i("onQueryTextChange", newText);

mAdapter.setFilter(filter(mNoticeContent.getNoticeList(), newText));
return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
Log.i("onQueryTextSubmit", query);

return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
}

return true;
}


private List<NoticeItem> filter(List<NoticeItem> noticeListItem, String query) {
query = query.toLowerCase();

final List<NoticeItem> filteredNoticeList = new ArrayList<>();
if (query != null && !query.equals("")) {
for (NoticeItem model : noticeListItem) {
final String title = model.getTitle().toLowerCase();
final String name = model.getName().toLowerCase();
if (title.contains(query)) {
filteredNoticeList.add(model);
}else if(name.contains(query)){
filteredNoticeList.add(model);
}
}
}
return filteredNoticeList;
}

}

---------------------------------------------------------------------------------------------------------------------

 

NoticeRecyclerAdapter

 

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

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

public NoticeRecyclerAdapter(Context context, List<NoticeItem> items) {
this.mContext = context;
mValues = items;
}

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


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

//이부분 중요!! 검색 리스트를 나오게하기 위해 꼭 필요
public void setFilter(List<NoticeItem> items) {
mValues.clear();
mValues.addAll(items);
notifyDataSetChanged();
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mItem = mValues.get(position);
holder.mTitleText.setText(mValues.get(position).getTitle());
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}


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

public NoticeItem mItem;

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

 


 

----------------------------------------------------------XML---------------------------------------------------

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




<android.support.v7.widget.Toolbar
android:id="@+id/notice_search_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="@color/white_color"
android:elevation="5dp"
app:contentInsetStartWithNavigation="0dp">




<android.support.v7.widget.SearchView
android:id="@+id/notice_search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


</android.support.v7.widget.Toolbar>



<android.support.v7.widget.RecyclerView
android:id="@+id/notice_search_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/notice_search_toolbar"/>



</RelativeLayout>


 

 


728x90
반응형

'Android' 카테고리의 다른 글

RecyclerView 만들기  (0) 2016.11.14
Activity와 Fragment간 데이터 전달  (0) 2016.11.14
android SHA1 알아내기  (0) 2016.10.19
Android TextView Line 가져오기  (0) 2016.09.21
안드로이드 StatusBar 높이 알아내기  (0) 2016.07.08
int android.widget.TextView.getLineCount()


Return the number of lines of text, or 0 if the internal Layout has not been built.
-내부 레이아웃이 내장되어 있지 않은 경우,텍스트 줄의 수를 돌려줍니다


getLineCount()메서드로 Parent View가 넓어지거나 줄어들어도 해당 메서드로 TextView글자 라인수를 가져 올 수 있습니다.


예를들어
--------------------------------------------------------------------------------------------------
String text = “가나다라마바사아자차카타파아야ABCDEFGHIJKLMNOPdfsgdsdfefsdfsdf.”

exTextView.setMaxLine(2);    //최대 라인 수 정의
 
exTextView.setText(text);        
-------------------------------------------------------------------------------------------------
위 코드를 실행했을때 만약 상위 뷰가 작아서 “”까지 밖에 보여줄 수 밖에  없을 경우
가나다라마바사
아자차카타파...
 
getLineCount()를 쓰면 “”이후 “...”으로 생략된 데이터까지 포함해서 라인 수를 가져옵니다

가나다라마바사
아자차카타파아
야ABCDEFGHIJ
KLMNOPdfsgd

sdfefsdfsdf


exTextView의 라인수 = 5를 가져옵니다.

728x90
반응형

public static int SCREEN_WIDTH = 0;

public static int SCREEN_HEIGHT = 0;


/**

* 소프트키를 포함한 화면 전체해상도를 가져온다.

* @param context

*/

public static void setScreenInfo(Context context){

if(Build.VERSION.SDK_INT>=14)

{

android.view.Display display = ((WindowManager) context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();

Point realSize = new Point();

try {

Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InvocationTargetException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (NoSuchMethodException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

SCREEN_WIDTH=realSize.x;

SCREEN_HEIGHT=realSize.y;

}else{

DisplayMetrics dmath=context.getResources().getDisplayMetrics(); // 화면의 가로,세로 길이를 구할 때 사용합니다.

SCREEN_WIDTH=dmath.widthPixels;

SCREEN_HEIGHT=dmath.heightPixels;

}

}


/**

* 소프트키를 미포함한 화면 전체해상도를 가져온다.

* @param context

*/

public static void setNoSoftKeyScreenInfo(Context context){

DisplayMetrics dmath=context.getResources().getDisplayMetrics(); // 화면의 가로,세로 길이를 구할 때 사용합니다.

SCREEN_WIDTH=dmath.widthPixels;

SCREEN_HEIGHT=dmath.heightPixels;

}


/**

* 소프트키 존재 여부를 가져온다.

* @param context

*/

public static boolean isScreenSoftKey(Context context) {

boolean isKey = false;

if (Build.VERSION.SDK_INT >= 14) {

boolean hasMenuKey = ViewConfiguration.get(context)

.hasPermanentMenuKey();

boolean hasBackKey = KeyCharacterMap

.deviceHasKey(KeyEvent.KEYCODE_BACK);


if (!hasMenuKey && !hasBackKey) {

isKey = true;

} else {

isKey = false;

}

} else {

isKey = false;

}

return isKey;

}

728x90
반응형

'Android' 카테고리의 다른 글

안드로이드 코드에서 마진 주기  (0) 2016.06.22
안드로이드 Px to Dip  (0) 2016.06.22
안드로이드 리스트 뷰 만들기  (0) 2016.01.25
버튼 Press 정의  (0) 2016.01.12
안드로이드 Menu 객체 만들기  (0) 2016.01.05

코딩을 하다보면 일반 레이아웃 객체는 쉽게 선언 할 수 있는데 안드로이드 툴바 메뉴객체는 어떻게 선언해야하지? 하면서 모

를 때가 있습니다. 이럴때는 이렇게 하시면 됩니다.


add_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="@+id/add_all_check"
android:title="@string/choice_all"
android:checkable="true"
android:checked="false"
android:orderInCategory="101"
app:showAsAction="ifRoom"
/>

<item
android:id="@+id/add_check_num"
android:title=""
android:orderInCategory="102"
app:showAsAction="ifRoom"
/>
</menu>

-----------------------------------------------------------------------------------------------------------------

/**전체선택 메뉴*/
private MenuItem mAddAllCheckMenu;

/**선택 개수 메뉴*/
private MenuItem mAddCheckNumMenu;


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_menu, menu);
mAddAllCheckMenu = menu.findItem(R.id.add_all_check);
mAddCheckNumMenu = menu.findItem(R.id.add_check_num);
mAddCheckNumMenu.setTitle(String.format(getString(R.string.choice_check_num), 0));
return true;
}


    @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Intent intent = null;
if (id == R.id.add_all_check) {
if (!mAddAllCheckMenu.isChecked()) {
mAddAllCheckMenu.setChecked(true);
mAddAllCheckMenu.setTitle(getString(R.string.choice_all));
setAllChecked(true);
mAddCheckNumMenu.setTitle(String.format(getString(R.string.choice_check_num), getCheckedCount()));
} else {
mAddAllCheckMenu.setChecked(false);
mAddAllCheckMenu.setTitle(getString(R.string.choice_all));
setAllChecked(false);
mAddCheckNumMenu.setTitle(String.format(getString(R.string.choice_check_num), 0));
}
} else if (id == R.id.add_check_num) {
return false;

}


return super.onOptionsItemSelected(item);
}
}


728x90
반응형

이번에는 GitHub에서 예제를 다운로드하는 방법에 대해서 알아볼것입니다.

GitHub이란?

GitHub의 친구, 동료, 급우, 완전한 낯선 사람과 코드를 공유 할 수있는 최고의 장소입니다. 많은 개발자들이 함께 놀라운 일들을 구축 하며 GitHub을 사용합니다.

GitHub.com, 우리의 데스크톱 응용 프로그램 및 GitHub의 기업의 협업 기능으로, 더 빨리, 더 나은 코드를 작성하는 개인과 팀을 위해 쉽게되어있다.

원래 공유 코드를 단순화하기 위해 톰 프레스턴 - 베르너, 크리스 Wanstrath 및 PJ Hyett에 의해 설립되었고
GitHub은 세계 최대의 코드 호스트로 성장했습니다.

아무튼 다른 사람들과의 개발을 협업할 수 있는 제일 좋은 방법이라 소개하는것 같군요

-홈페이지에서 발췌 

-공식 사이트 https://github.com/

아무튼 이제 GitHub에 있는 방대한 자료들을 다운로드 해볼까요?

1.Github 홈페이지에 들어가면 다음과 같이 화면이 보입니다.
  검색창에 다음과같이 원하는 위젯명이나 소스명 등등...을 입력해줍니다.
  저는 LIstView를 검색해 보겟습니다.


2.ListView를 검색해보면 여러가지 예제소스나 라이브러리 리스트가 나타납니다. 
  ① 예제소스나 라이브러리 리스트
  ② 작성된 언어
  ③ 별은 즐겨찾기 그옆에는 공유한 숫자를 뜻하는것 같군요
  우선 저는 별표가 많아보이는(보통 별표가 많을수록 제대로된 소스더군요)

beworker/pinned-section-listview

두번째 여기로 들어가보겟습니다.


3. 들어가보니 다음과 같이 zip파일로 다운 받거나 git로 복사할수있게 되어있네요
   그리고 밑에부분에는 스크린샷이 찍혀져 잇네요~
 



4. 요즘은 이렇게 요기에서 다운 받을 수 있네요


아무튼 간단하게 GitHub에서 예제를 다운로드 받을수있는 방법에 대해서 얘기했습니다.
부족하지만 많은정보를 얻어 가시길;;









728x90
반응형



안녕하세요 이제 막 시작한블로거 입니다.

이번에는 카메라 크롭관련예제 링크를 올릴건데요

저도 이소스를 보고 많이 도움되고 덕분에 카메라 크롭기능을 완성시킬수 있었습니다.

 

 

 


출처는 이곳입니다.
https://github.com/lvillani/android-cropimage

즐거운 코딩하시길바랍니다.

728x90
반응형

핀터레스트 레이아웃입니다.

핀터레스트는 "Pinterest" 라는 미국 소셜 네트워크 서비스에서 유래됐다고 하는데요

음... 뭐 아무튼 한번 플레이스토어에 가셔서 보시는 것도 나쁘지않을거라 생각됩니다.

https://play.google.com/store/apps/details?id=com.pinterest

예제의 스크린샷입니다.


예제 다운로드 주소는

https://github.com/etsy/AndroidStaggeredGrid

 


 

728x90
반응형

+ Recent posts