Android FlipView Scrolling Back and Front Page with Button - android

I want to flip between two fragment with button click.and stop touch action.
using
android-flip,
issue link.
Sample of my code
public class FlipFragmeent extends Fragment{
private int currentFragmentIndex;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
flipView = new FlipViewController(inflater.getContext(),
FlipViewController.HORIZONTAL);*emphasized text*
//flipView.setFlipByTouchEnabled(false);
flipView.setAdapter(new BaseAdapter() {
#Override
public int getCount() {
return 4;
}
#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) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) battleActivity
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(
R.layout.fragment_next, null);
((Button)convertView.findViewById(R.id.next)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
flipView.refreshPage(currentFragmentIndex);
currentFragmentIndex++;
if(currentFragmentIndex == 4)
currentFragmentIndex = 0;
}
}));
return convertView;
}
});
return flipView;
}
BUT that does not work any help?

Related

How to do Multiple Choice Using GridView android?

This is how I do my Gridview with adapter, can someone tell me how can I modify these code to get the multiple choice effect ? Following is my code, kindly advise and thousand of thanks provided.
//privateList<Condiment> CondimentList;
CondimentList = getCondimentDescription(productcode);
condimentGrid.setAdapter(new condimentlist());
public class condimentlist extends BaseAdapter {
LayoutInflater mInflater;
public condimentlist() {
mInflater = LayoutInflater.from(cart_list.this);
}
#Override
public int getCount() {
return CondimentList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.condiment_item, null);
}
Condiment myObj = CondimentList.get(position);
Button CondimentItem = (Button) convertView.findViewById(R.id.condimentItem);
CondimentItem.setText("" +myObj.getCondimentDescription());
return convertView;
}
}
Just little addition in your code provide selected value in your Condiment class model and use like this.
//privateList<Condiment> CondimentList;
CondimentList = getCondimentDescription(productcode);
condimentGrid.setAdapter(new condimentlist());
public class condimentlist extends BaseAdapter {
LayoutInflater mInflater;
public condimentlist() {
mInflater = LayoutInflater.from(cart_list.this);
}
#Override
public int getCount() {
return CondimentList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.condiment_item, null);
}
final Condiment myObj = CondimentList.get(position);
Button CondimentItem = (Button) convertView.findViewById(R.id.condimentItem);
CondimentItem.setText("" +myObj.getCondimentDescription());
CondimentItem.setSelected(myObj.isSelected());
CondimentItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myObj.setSelected(!myObj.isSelected());
v.setSelected(myObj.isSelected());
}
});
return convertView;
}
}

get swiped image position in swipe cards [Tinder Swipe]

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);

GridView with buttons scale to size

I have problem with my gridview filled with button. Size of buttons are different when I user match_parent, when I set fixed size it looks good, but not on all screen sizes. Maybe I should use other component than buttons? This is my code.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.myfragment, container,
false);
GridView myfragment_grid = (GridView) rootView.findViewById(R.id.myfragment_grid);
myfragment_grid.setAdapter(new GridAdapter(getActivity()));
return rootView;
}
public class GridAdapter extends BaseAdapter {
public GridAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 12;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
String[] labels = getActivity().getResources().getStringArray(
R.array.grid_labels);
Button menuButton;
if (convertView == null) {
menuButton = new Button(mContext);
menuButton.setBackgroundColor(getResources().getColor(
R.color.grid_item_color));
menuButton.setTextColor(getResources().getColor(R.color.white));
menuButton.setTextSize(15);
menuButton.setText(labels[position]);
menuButton.setLayoutParams(new GridView.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
menuButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
switch (position) {
...
}
}
});
} else {
menuButton = (Button) convertView;
}
return menuButton;
}
private Context mContext;
}

Gridview custom adapter button onclick

My gridview custom item is a image button.I want to change image button image when the image button is clicked.You can see below my custom adapter class getView method.But image button image does not change.
ImageButton btn1;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.myItem, null);
btn1 = (ImageButton) view.findViewById(R.id.btn1);
}
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
btn1.setImageResource(R.id.image1);
}
});
return view;
}
Try this way,hope this will help you to solve your problem.
public class CustomGridAdapter extends BaseAdapter {
private Context context;
private ArrayList<HashMap<String,Integer>> imagesList;
public CustomGridAdapter(Context context,ArrayList<HashMap<String,Integer>> imagesLis) {
this.context =context;
this.imagesList =imagesLis;
}
#Override
public int getCount() {
return imagesList.size();
}
#Override
public Object getItem(int position) {
return imagesList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.myItem, null);
holder.btn1 = (TextView) convertView.findViewById(R.id.btn1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.btn1.setImageResource(imagesList.get(position).get("normalImage"));
holder.btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((ImageButton)v).setImageResource(imagesList.get(position).get("selectedImage"));
}
});
return convertView;
}
static class ViewHolder {
ImageButton btn1;
}
}

Using StickyGridHeaders

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;
}
}

Categories

Resources