StickyGridHeaders, but its not working as it should, or at least as I want.
So I got this list with other lists inside, and with that i create a header list(I use the original list) and a full items list (all the subitems), and the call the adapter like so:
List<CalendarDate.CalendarTvShowEpisode> lista=new LinkedList<CalendarDate.CalendarTvShowEpisode>();
for(CalendarDate l:response){
lista.addAll(l.episodes);
}
setListAdapter(new WeekCalendarAdapter(getActivity(), weekCalendar,lista));
Then i have my Adapter:
public class WeekCalendarAdapter extends BaseAdapter implements StickyGridHeadersBaseAdapter {
private final List<CalendarDate> mListHeaders;
private final List<CalendarDate.CalendarTvShowEpisode> lista;
private LayoutInflater inflater;
public WeekCalendarAdapter(Context context, List<CalendarDate> mList, List<CalendarDate.CalendarTvShowEpisode> lista) {
this.mListHeaders = mList;
this.lista=lista;
inflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return lista.size();
}
#Override
public Object getItem(int i) {
return lista.get(i);
}
#Override
public long getItemId(int i) {
return lista.get(i).episode.firstAired.getDay();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.calendarweek_item_episode, parent, false);
}
AQuery aq= new AQuery(convertView);
aq.id(R.id.imageViewCalendarEpisodeBackdrop).image(lista.get(position).episode.images.screen);
aq.id(R.id.textViewCalendartext).text(lista.get(position).episode.firstAired.getDay()+"");
return convertView;
}
#Override
public int getCountForHeader(int header) {
return mListHeaders.get(header).episodes.size();
}
#Override
public int getNumHeaders() {
return mListHeaders.size();
}
#Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.calendarweek_item, parent, false);
}
AQuery aq = new AQuery(convertView);
SimpleDateFormat format = new SimpleDateFormat("E MM dd, yyyy");
aq.id(R.id.textViewCalendarWeekDay).text(format.format(mListHeaders.get(position).date) + "");
return convertView;
}
The result I get is just a normal listview with all items ordered on below another, no gridview nor header.
What I'm a doing wrong?
Finally found out how to do it.
And the main problem is that it cant be a listfragment because, well listfragment has a listview. It has to be a Fragment and then your view need to have a com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView
So the code:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.calendarweek_fragment, container, false);
StickyGridHeadersGridView l = (StickyGridHeadersGridView) rootView.findViewById(R.id.listViewCalendar);
mAdapter = new WeekCalendarAdapter(getActivity(), weekCalendar, lista);
l.setAdapter(mAdapter);
return rootView;
}
And the View:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView
android:id="#+id/listViewCalendar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="160dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:gravity="left"
android:background="#color/calendar_background"/>
</LinearLayout>
My adapter
public class WeekCalendarAdapter extends BaseAdapter implements StickyGridHeadersBaseAdapter {
private final List<CalendarDate> mListHeaders;
private final List<CalendarDate.CalendarTvShowEpisode> lista;
private LayoutInflater inflater;
public WeekCalendarAdapter(Context context, List<CalendarDate> mList, List<CalendarDate.CalendarTvShowEpisode> lista) {
this.mListHeaders = mList;
this.lista = lista;
inflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return lista.size();
}
#Override
public CalendarDate.CalendarTvShowEpisode getItem(int i) {
return lista.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.calendarweek_item_episode, parent, false);
}
//EDIT YOUR GRID ITEM HERE
return convertView;
}
#Override
public int getCountForHeader(int i) {
return mListHeaders.get(i).episodes.size();
}
#Override
public int getNumHeaders() {
return mListHeaders.size();
}
#Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.calendarweek_item, parent, false);
}
//EDIT YOUR VIEW HEADER HERE
return convertView;
}
}
Related
How to set spinner List first position value showing empty, i attached the adapter and activity: kindly resolve my problem.
SpinnerAdapterIdtypeMaster
public class SpinnerAdapterIdtypeMaster extends ArrayAdapter {
private Context mContext;
private List<CMSSubMasterDB> spinnerList = new ArrayList<>();
private MasterType type;
public SpinnerAdapterIdtypeMaster(#NonNull Context context, List<CMSSubMasterDB> list) {
super(context, 0, list);
mContext = context;
spinnerList = list;
}
#Override
public View getDropDownView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
#Override
public int getCount() {
return spinnerList.size();
}
#Nullable
#Override
public CMSSubMasterDB getItem(int position) {
return spinnerList.get(position);
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
View listItem = convertView;
if (listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);
CMSSubMasterDB currentMovie = spinnerList.get(position);
TextView name = (TextView) listItem.findViewById(R.id.spinner);
name.setText(currentMovie.name);
return listItem;
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//return super.getView(position, convertView, parent);
View listItem = convertView;
if (listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);
TextView label = (TextView) listItem.findViewById(R.id.spinner);
label.setText(spinnerList.get(position).name);
return listItem;
}
}
CreateRyotManagerFragment
public class CreateRyotManagerFragment extends Fragment {
Spinner mIDType
List<CMSSubMasterDB> mIdtypeMasterList;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.layout_new_ryot, container, false);
mIDType = view.findViewById(R.id.idtype);
mIdtypeMasterList = AppUtils.getIDTypeMasterDb();
SpinnerAdapterIdtypeMaster idTypeMaster = new SpinnerAdapterIdtypeMaster(getActivity().getApplicationContext(), mIdtypeMasterList);
mIDType.setAdapter(idTypeMaster);
return view;
}
}
Try this code,
List<CMSSubMasterDB> mIdtypeMasterList = new List<CMSSubMasterDB>;
CMSSubMasterDB cmsdb = new CMSSubMasterDB();
cmsdb.setName("Select value");
mIdtypeMasterList.add(cmsdb);
List<CMSSubMasterDB> mIdList =AppUtils.getIDTypeMasterDb();
for (int i=0;i<mIdList.size();i++){
mIdtypeMasterList.add(mIdList.get(i));
}
SpinnerAdapterIdtypeMaster idTypeMaster = new
SpinnerAdapterIdtypeMaster(getActivity().getApplicationContext(),
mIdtypeMasterList);
mIDType.setAdapter(idTypeMaster);
mIDType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
mgetdatacall(position);
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
private void mgetdatacall(int position) {
if(position != 0) {
mIdList.get(position - 1).getname();
}
}
I have 3 fragments with gridview but onclikitem event does not work.
What might be the problem?
I did my best and I tried all of them but not true. I think the problem is the use of fragments because with use activity works fine.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.free_video_fragment, container, false);
final GridView gridview = (GridView) view.findViewById(R.id.freevideogridview);
List<ItemObject> allItems = getAllItemObject();
CustomAdapter customAdapter = new CustomAdapter(getActivity(), allItems);
gridview.setAdapter(customAdapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {
Toast.makeText(getActivity(),"Position" , Toast.LENGTH_LONG).show();
}
});
return view;
Layout:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/freevideogridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:horizontalSpacing="4dp"
android:numColumns="3"
android:padding="4dp"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp"
/>
Adapter:
public class CustomAdapter extends BaseAdapter {
private LayoutInflater layoutinflater;
private List<ItemObject> listStorage;
private Context context;
public CustomAdapter(Context context, List<ItemObject> customizedListView) {
this.context = context;
layoutinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
listStorage = customizedListView;
}
#Override
public int getCount() {
return listStorage.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder listViewHolder;
if(convertView == null){
listViewHolder = new ViewHolder();
convertView = layoutinflater.inflate(R.layout.pop_music_list, parent, false);
listViewHolder.screenShot = (ImageView)convertView.findViewById(R.id.screen_shot);
listViewHolder.musicName = (TextView)convertView.findViewById(R.id.music_name);
listViewHolder.musicAuthor = (TextView)convertView.findViewById(R.id.music_author);
convertView.setTag(listViewHolder);
}else{
listViewHolder = (ViewHolder)convertView.getTag();
}
listViewHolder.screenShot.setImageResource(listStorage.get(position).getScreenShot());
listViewHolder.musicName.setText(listStorage.get(position).getMusicName());
listViewHolder.musicAuthor.setText(listStorage.get(position).getMusicAuthor());
return convertView;
}
static class ViewHolder{
ImageView screenShot;
TextView musicName;
TextView musicAuthor;
}
}
I think you have to change in your adapter like below.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder listViewHolder;
if(convertView == null){
listViewHolder = new ViewHolder();
convertView = layoutinflater.inflate(R.layout.pop_music_list, parent, null);
listViewHolder.screenShot = (ImageView)convertView.findViewById(R.id.screen_shot);
listViewHolder.musicName = (TextView)convertView.findViewById(R.id.music_name);
listViewHolder.musicAuthor = (TextView)convertView.findViewById(R.id.music_author);
convertView.setTag(listViewHolder);
}else{
listViewHolder = (ViewHolder)convertView.getTag();
}
listViewHolder.screenShot.setImageResource(listStorage.get(position).getScreenShot());
listViewHolder.musicName.setText(listStorage.get(position).getMusicName());
listViewHolder.musicAuthor.setText(listStorage.get(position).getMusicAuthor());
return convertView;
}
put null in place of false at where you inflate your view.
I am working on tinder swipe cards library.So I referred this Sample.
My issue is, while swiping image I need to get the swiped image position.So far I tried like int idGet = flingContainer.getSelectedItemPosition(); But it is not working for me.
Below I have posted relevant code :
Logcat:
E:/ idGet : -1
CardsFragment.java:
public class CardsFragment extends Fragment {
private SwipeFlingAdapterView flingContainer;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
flingContainer = (SwipeFlingAdapterView) rootView.findViewById(R.id.frame);
likeImg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
likeNope();
flipMethodRight(80.00f);
}
});
}
}
void flipMethodRight(float scrollProgressPercent) {
flingContainer.getTopCardListener().selectRight();
View view = flingContainer.getSelectedView();
view.findViewById(R.id.background).setAlpha(0);
view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
}
public class MyAppAdapter extends BaseAdapter {
public List<GetImageData> parkingList;
public Context context;
private MyAppAdapter(List<GetImageData> apps, Context context) {
this.parkingList = apps;
this.context = context;
}
#Override
public int getCount() {
return parkingList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater =getActivity(). getLayoutInflater();
rowView = inflater.inflate(R.layout.adapt_card_frag, parent, false);
Log.e("AdapterCalling", "AdapterCalling");
// configure view holder
viewHolder = new ViewHolder();
viewHolder.DataText = (TextView) rowView.findViewById(R.id.bookText);
viewHolder.background = (FrameLayout) rowView.findViewById(R.id.background);
viewHolder.cardImage = (ImageView) rowView.findViewById(R.id.cardImage);
Log.e("ParkingList", "" +parkingList.get(position).getDescription() + "");
int idGet = flingContainer.getSelectedItemPosition();
Log.e("idGet", ""+idGet);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.DataText.setText(parkingList.get(position).getDescription() + "");
Glide.with(CardsFragment.this).load(parkingList.get(position).getImagePath()).into(viewHolder.cardImage);
return rowView;
}
}
I solved this issue with the help of below code:
String getImageFlingStr, GET_PRESENT_IMAGE;
getImageFlingStr = nameImgArrList.get(0).getImagePath();
presentImageShowing = getImageFlingStr;
GET_PRESENT_IMAGE = presentImageShowing;
Log.e("presentImageShowing", ""+presentImageShowing);
I have a problem with Android Spinner. I customised an adapter with a BaseAdapter. But when it show in the first time, it not show all items (I have only 6 items). Below is the screenshot
http://pik.vn/2014999186b9-448d-44ed-bd9b-c37484b368c6.png
And when I tap to the Spinner second time it show normally. Below is the screenshot. How can I show full item like that at the first time?
http://pik.vn/201454ed3e5b-4c67-4e9c-b8c6-feaf90c5dfb4.png
Update code:
Below is the adapter:
public class CategoryAdapter extends BaseAdapter implements SpinnerAdapter {
Context mContext;
List<CategoryModel> data;
int selectedCate;
boolean isSpinner;
Spinner spn;
public CategoryAdapter(Context context, List<CategoryModel> data, boolean isSpinner, Spinner spn) {
mContext = context;
selectedCate = 0;
this.data = data;
this.isSpinner=isSpinner;
this.spn = spn;
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
if (position < data.size()) {
return data.get(position);
} else {
return null;
}
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.inflater_category_spinner, parent, false);
}
TextView tvName = (TextView) convertView.findViewById(R.id.inflater_category_spinner_tv);
tvName.setSelected(spn.isSelected());
tvName.setText(data.get(position).getName());
return convertView;
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.inflater_category, parent, false);
ImageView img = (ImageView) convertView.findViewById(R.id.inflater_cate_image);
if (!data.get(position).getName().equals(parent.getContext().getString(R.string.browse))) {
Log.d("postion", "" + position);
UrlImageViewHelper.setUrlDrawable(img, data.get(position).getImage().getUrl());
} else {
img.setImageResource(R.drawable.ic_everything);
}
TextView tvName = (TextView) convertView.findViewById(R.id.inflater_cate_tv_name);
tvName.setText(data.get(position).getName());
return convertView;
}
public void swapView(int position) {
selectedCate = position;
}
}
and below is the code init Spinner in Activity
categoryAdapter = new CategoryAdapter(HomeActivity.this, result,true, mSpnActionbarCenterTitle);
mSpnActionbarCenterTitle.setAdapter(categoryAdapter);
The problem comes from the height of ImageView, it is wrap content and load via lazy loader, and the height of spinner not change when image loaded. My solution is fix the size of ImageView.
Im using a listView that have 2 layouts for the rows on one row the
setOnItemClickListener
but on the other row it doesnt recognize the taps,
public void initItemTable()
{
listViewItem = (ListView) getView().findViewById(R.id.listViewItem);
listViewItem.setAdapter(new PhoneItemAdapter(new ItemPhoneDataSource().getItems()));
listViewItem.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Log.d("mensa", "item index :"+arg2);
}
});
}
//
private class PhoneItemAdapter extends BaseAdapter {
final List<RowPhone> rows;//row
//data source, style
PhoneItemAdapter(List<ItemPhone> animals) {
rows = new ArrayList<RowPhone>();//member variable
//choose cell! iterator
for (ItemPhone item : animals) {
if (item.getType().equals("item")) {
rows.add(new RowItemPhone(LayoutInflater.from(getActivity()), item));
} else {
rows.add(new RowFolderPhone(LayoutInflater.from(getActivity()), item)); //imageRow!
}
}
}
//delegate
#Override
public int getViewTypeCount() {
return RowTypePhone.values().length;
}
#Override
public int getItemViewType(int position) {
//con cast
return ((RowPhone) rows.get(position)).getViewType();
}
public int getCount() {
return rows.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//cambiado con cast!
return ((RowPhone) rows.get(position)).getView(convertView);
}
}
So the tap is detected when "item.getType()" is folder but not in item,
. Shall I include the code for RowItemPhone.java and RowFolderPhone.java?
so how to fix this tap problem?
thanks!
edit 1. RowPhone.java
public interface RowPhone {
public View getView(View convertView);
public int getViewType();
}
edit 2. RowFolder.java .. the one that have the tap detecting fine:
public class RowItemPhone implements RowPhone{
private final ItemPhone item;
private final LayoutInflater inflater;
public RowItemPhone(LayoutInflater inflater, ItemPhone animal) {
this.item = animal;
this.inflater = inflater;
}
//text doble
public View getView(View convertView) {
ViewHolder holder;
View view = null;
if (convertView == null) {
//ViewGroup viewGroup = (ViewGroup)inflater.inflate(R.layout.row_item_phone, null);
ViewGroup viewGroup = (ViewGroup)inflater.inflate(R.layout.row_item_phone, (ViewGroup) view, false);
holder = new ViewHolder(
(ImageView)viewGroup.findViewById(R.id.image_item),
(TextView)viewGroup.findViewById(R.id.title),
(TextView)viewGroup.findViewById(R.id.description));
viewGroup.setTag(holder); //pa q y como usa tag!
view = viewGroup;
} else {
view = convertView;
holder = (ViewHolder)convertView.getTag();
}
//setup
holder.imageView.setImageResource(item.getImageId());
holder.descriptionView.setText(item.getDescription());
holder.titleView.setText(item.getName());
return view;
}
public int getViewType() {
return RowTypePhone.DESCRIPTION_ROW.ordinal();
}
private static class ViewHolder {
final ImageView imageView;
final TextView titleView;
final TextView descriptionView;
private ViewHolder(ImageView imageView, TextView titleView, TextView descriptionView) {
this.imageView = imageView;
this.titleView = titleView;
this.descriptionView = descriptionView;
}
}
}
And here the RowFolderPhone.java ... showing fine, but not detecting taps:
public class RowFolderPhone implements RowPhone {
private final ItemPhone item;
private final LayoutInflater inflater;
public RowFolderPhone(LayoutInflater inflater, ItemPhone animal) {
this.item = animal;
this.inflater = inflater;
}
public View getView(View convertView) {
ViewHolder holder;
View view = null;
//we have a don't have a converView so we'll have to create a new one
if (convertView == null) {
// ViewGroup viewGroup = (ViewGroup)inflater.inflate(R.layout.row_folder_phone, null);
ViewGroup viewGroup = (ViewGroup)inflater.inflate(R.layout.row_folder_phone, (ViewGroup) view, false);
//use the view holder pattern to save of already looked up subview
holder = new ViewHolder((ImageView)viewGroup.findViewById(R.id.image),
(TextView)viewGroup.findViewById(R.id.title));
viewGroup.setTag(holder);
view = viewGroup;
} else {
//get the holder back out
holder = (ViewHolder)convertView.getTag();
view = convertView;
}
//actually setup the view
holder.imageView.setImageResource(item.getImageId());
holder.titleView.setText(item.getName());
return view;
}
public int getViewType() {
return RowTypePhone.IMAGE_ROW.ordinal();
}
private static class ViewHolder {
final ImageView imageView;
final TextView titleView;
private ViewHolder(ImageView imageView, TextView titleView) {
this.imageView = imageView;
this.titleView = titleView;
}
}
}
There are something wrong with your getItem method on PhoneItemAdapter. getItem method should return list item not position. So you should replace your code to
public RowPhone getItem(int position) {
return rows.get(position);
}
the problem was solved by setting descendantFocusability
in : row_item_phone.xml
<RelativeLayout ...
android:descendantFocusability="blocksDescendants"