Custom adapter not display default text in spinner item - android

I want to display select all as default text in first spinner and for this I used custom adapter but I am unable to do this.
I set code of adapter to bind data in spinner like this:
private void getClientGroup() {
final APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);
final FilterModel filterModel = new FilterModel("G", String.valueOf(clientid), String.valueOf(loginid), "A", String.valueOf(userrole));
Call<FilterModel> call1 = apiInterface.createClientGroup(filterModel);
call1.enqueue(new Callback<FilterModel>() {
#Override
public void onResponse(Call<FilterModel> call, Response<FilterModel> response) {
FilterModel filterResponse = response.body();
Log.e("Getclientgroup:", "success");
for (int i = 0; i < filterResponse.getT0().size(); i++) {
int groupId = filterResponse.getT0().get(i).getID();
String groupText = filterResponse.getT0().get(i).getTEXT();
Log.e("Groupid==", String.valueOf(groupId));
Log.e("GroupText==", String.valueOf(groupText));
groupTextList.add(groupText);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, android.R.id.text1, groupTextList);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spGroup.setAdapter(
new NothingSelectedSpinner(
dataAdapter,
R.layout.nothing_selected_spinner_item, 0,
getActivity()));
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(R.layout.nothing_selected_spinner_item);
// attaching data adapter to spinner
spGroup.setAdapter(dataAdapter);
}
}
#Override
public void onFailure(Call<FilterModel> call, Throwable t) {
Log.e("Error is==", t.getMessage());
}
});
I am using Nothingselected adapter for this:
public class NothingSelectedSpinner implements SpinnerAdapter, ListAdapter {
protected static final int EXTRA = 1;
protected SpinnerAdapter adapter;
protected Context context;
protected int nothingSelectedLayout;
protected int nothingSelectedDropdownLayout;
protected LayoutInflater layoutInflater;
public NothingSelectedSpinner(SpinnerAdapter spinnerAdapter,
int nothingSelectedLayout, int nothingSelectedDropdownLayout, Context context) {
this.adapter = spinnerAdapter;
this.context = context;
this.nothingSelectedLayout = nothingSelectedLayout;
this.nothingSelectedDropdownLayout = nothingSelectedDropdownLayout;
layoutInflater = LayoutInflater.from(context);
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return null;
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public final View getView(int position, View convertView, ViewGroup parent) {
// This provides the View for the Selected Item in the Spinner, not
// the dropdown (unless dropdownView is not set).
if (position == 0) {
return getNothingSelectedView(parent);
}
return adapter.getView(position - EXTRA, null, parent); // Could re-use
// the convertView if possible.
}
protected View getNothingSelectedDropdownView(ViewGroup parent) {
return layoutInflater.inflate(nothingSelectedDropdownLayout, parent, false);
}
#Override
public int getItemViewType(int position) {
return 0;
}
#Override
public int getViewTypeCount() {
return 1;
}
#Override
public long getItemId(int position) {
return position >= EXTRA ? adapter.getItemId(position - EXTRA) : position - EXTRA;
}
#Override
public boolean hasStableIds() {
return adapter.hasStableIds();
}
#Override
public boolean isEmpty() {
return adapter.isEmpty();
}
#Override
public void registerDataSetObserver(DataSetObserver observer) {
adapter.registerDataSetObserver(observer);
}
#Override
public void unregisterDataSetObserver(DataSetObserver observer) {
adapter.unregisterDataSetObserver(observer);
}
#Override
public boolean areAllItemsEnabled() {
return false;
}
#Override
public boolean isEnabled(int position) {
return position != 0; // Don't allow the 'nothing selected'
// item to be picked.
}
protected View getNothingSelectedView(ViewGroup parent) {
return layoutInflater.inflate(nothingSelectedLayout, parent, false);
}
}
and layout for this adapter is:
<TextView
android:id="#+id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:padding="#dimen/dp10"
android:textSize="#dimen/dp30"
android:textColor="#color/colorBlack"
android:text="Select all" />
and main layout of spinner is:
<LinearLayout
android:id="#+id/ll_filter_report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginTop="#dimen/dp20"
android:layout_marginRight="#dimen/dp20"
android:background="#drawable/rounded_layout_white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ll_sub_group"
android:layout_width="match_parent"
android:layout_height="#dimen/dp80"
android:orientation="horizontal"
android:padding="#dimen/dp20"
android:weightSum="1">
<TextView
android:id="#+id/lbl_sub_group"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="left|center"
android:text="#string/str_sub_group"
android:textSize="#dimen/dp20" />
<Spinner
android:id="#+id/spn_sub_group"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"></Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_client"
android:layout_width="match_parent"
android:layout_height="#dimen/dp80"
android:layout_marginTop="#dimen/dp10"
android:orientation="horizontal"
android:padding="#dimen/dp20"
android:weightSum="1">
<TextView
android:id="#+id/lbl_client"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="left|center"
android:text="#string/str_client"
android:textSize="#dimen/dp20" />
<Spinner
android:id="#+id/spn_client"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"></Spinner>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_date"
android:layout_width="match_parent"
android:layout_height="#dimen/dp80"
android:layout_marginTop="#dimen/dp10"
android:orientation="horizontal"
android:padding="#dimen/dp20"
android:weightSum="1">
<TextView
android:id="#+id/lbl_date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="left|center"
android:text="#string/str_as_on"
android:textSize="#dimen/dp20" />
<EditText
android:id="#+id/edt_date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:hint="02/01/2019"
android:padding="#dimen/dp10"></EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp20"
android:orientation="horizontal"
android:padding="#dimen/dp10"
android:weightSum="1">
<Button
android:id="#+id/btn_Search"
android:layout_width="#dimen/dp0"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#color/colorLightBlue"
android:text="#string/str_search"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/btn_reset"
android:layout_width="#dimen/dp0"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp10"
android:layout_weight="0.5"
android:background="#color/colorLightBlue"
android:text="#string/str_reset"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>
</LinearLayout>
I want to display all the items in second spinner if I select default text select all at index 0 of first spinner how I do this?

Related

Center ViewGroup views with Android-DraggableGridViewPager

I want to thanks zzhouj first of all, but I'm trying to use his Android-DraggableGridViewPager with some errors. this is his class:
Android-DraggableGridViewPager RAW
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<TextClock
android:gravity="center"
android:textColor="#color/colorBlack"
android:id="#+id/text_clock"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:fontFamily="sans-serif-black"
android:text="20:15"
android:textSize="50sp"
android:textStyle="bold" />
<TextView
android:gravity="center"
android:id="#+id/text_date"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:fontFamily="sans-serif-thin"
android:text="09/09/09"
android:textColor="#color/colorBlack"
android:textSize="20sp" />
<com.kangel.hybridlauncher.adapters.AppDraggableGridViewPager
android:foregroundGravity="center"
android:id="#+id/draggable_grid_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="75"
android:background="#color/colorAccent"
android:gravity="center" />
</LinearLayout>
I'm using it to create a simple gridview with draggable layout in, but if I reduce size of that ViewGroup, the element wont stay in center, because elements go on the left.
Do you have any ideas? Thanks in advance!
EDIT
public class AppArrayAdapter extends ArrayAdapter<AppObject> {
private Context context;
public AppArrayAdapter(#NonNull Context context, int resource) {
super(context, resource);
this.context = context;
}
#Override
public long getItemId(int position) {
return position;
}
#NonNull
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.gridview_app_layout, parent, false);
} else {
v = convertView;
}
LinearLayout layout = v.findViewById(R.id.single_item_core);
ImageView icon = layout.findViewById(R.id.app_layout);
TextView label = layout.findViewById(R.id.app_label);
final AppObject appObject = this.getItem(position);
icon.setImageDrawable(appObject.getIcon());
label.setText(appObject.getName());
return v;
}
#Override
public void add(#Nullable AppObject object) {
super.add(object);
notifyDataSetChanged();
}
#Override
public void addAll(#NonNull Collection<? extends AppObject> collection) {
super.addAll(collection);
notifyDataSetChanged();
}
#Override
public void addAll(AppObject... items) {
super.addAll(items);
notifyDataSetChanged();
}
#Override
public void insert(#Nullable AppObject object, int index) {
super.insert(object, index);
notifyDataSetChanged();
}
#Override
public void remove(#Nullable AppObject object) {
super.remove(object);
notifyDataSetChanged();
}
#Override
public void clear() {
super.clear();
notifyDataSetChanged();
}
}
EDIT
I set adapter in MainActivity:
DraggableGridViewPager mDraggableGridViewPager = mViewAppsScroll.findViewById(R.id.draggable_grid_view_pager);
mAppAdapter = new AppArrayAdapter(this, 0);
mAppAdapter.addAll(getList());
mDraggableGridViewPager.setAdapter(mAppAdapter);

ViewPager inside RecylerView, click not working

My RecyclerView's item layout has a ViewPager on top and some views below it. ViewPager works fine, swipes good. But the recycler item click is not working on clicking the ViewPager (I've set click on the entire item). But if I click the content below the ViewPager, Click works.
here's the RecyclerView's list item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="horizontal"
xmlns:attrs="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#android:color/white"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="6dp"
card_view:cardUseCompatPadding="true"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="0dp" android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintDimensionRatio="H,4:2"/>
<com.rd.PageIndicatorView
android:id="#+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="20dp"
app:piv_animationType="scale"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
app:piv_selectedColor="#color/whiteSmoke"
app:piv_unselectedColor="#color/white25Transparent"
app:piv_viewPager="#id/viewPager"
attrs:piv_padding="2dp"
attrs:piv_radius="4dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#id/viewpager" android:layout_marginBottom="0dp"/>
<com.codeairs.wattamatte.customcontrols.textview.MPRegularTextView
android:id="#+id/name"
android:layout_width="0dp" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/viewpager" android:layout_marginTop="6dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="12dp" android:layout_marginLeft="12dp"
android:layout_marginEnd="12dp" android:layout_marginRight="12dp"
android:text="Cosy Duplex - 42m2" android:textColor="#color/stPatricksBlue"/>
<com.codeairs.wattamatte.customcontrols.textview.MPMediumTextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/RoomDimensTextView"
app:layout_constraintTop_toBottomOf="#id/name" android:layout_marginTop="6dp"
app:layout_constraintStart_toStartOf="#id/name"
android:text="3p"/>
<com.codeairs.wattamatte.customcontrols.textview.MPMediumTextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/RoomDimensTextView"
app:layout_constraintTop_toBottomOf="#id/name" android:layout_marginTop="6dp"
app:layout_constraintStart_toEndOf="#id/tv1"
android:layout_marginStart="12dp" android:layout_marginLeft="12dp"
android:text="2ch"/>
<com.codeairs.wattamatte.customcontrols.textview.MPMediumTextView
android:id="#+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/RoomDimensTextView"
app:layout_constraintTop_toBottomOf="#id/name" android:layout_marginTop="6dp"
app:layout_constraintStart_toEndOf="#id/tv2"
android:layout_marginStart="12dp" android:layout_marginLeft="12dp"
android:text="4m"/>
<com.codeairs.wattamatte.customcontrols.textview.MPRegularTextView
android:id="#+id/location"
android:layout_width="0dp" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tv1" android:layout_marginTop="6dp"
app:layout_constraintStart_toStartOf="#id/tv1" app:layout_constraintEnd_toEndOf="parent"
android:text="Villeurbanne" android:textColor="#color/darkSlateBlue"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="4dp"/>
<com.codeairs.wattamatte.customcontrols.textview.MPBoldTextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="12dp"
android:text="450€ C.C" android:textColor="#color/stPatricksBlue" android:textSize="17sp"/>
<View
android:id="#+id/toggleBG"
android:layout_width="36dp" android:layout_height="36dp"
android:background="#drawable/solid_white_circle"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
app:layout_constraintTop_toBottomOf="#id/viewpager"
app:layout_constraintBottom_toBottomOf="#id/viewpager"/>
<ToggleButton
android:id="#+id/favoritesToggleButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/bg_fav_toggle"
android:textOn=""
android:textOff=""
app:layout_constraintTop_toTopOf="#id/toggleBG"
app:layout_constraintBottom_toBottomOf="#id/toggleBG"
app:layout_constraintStart_toStartOf="#id/toggleBG"
app:layout_constraintEnd_toEndOf="#id/toggleBG"/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
RecylerView Adapter
public class RoomsListRecyclerViewAdapter extends RecyclerView.Adapter<RoomsListRecyclerViewAdapter.ViewHolder> {
private final List<Room> mValues;
private final List<String> favRoomsIds;
private final OnListFragmentInteractionListener mListener;
private final Context mContext;
public RoomsListRecyclerViewAdapter(List<Room> items, List<String> favRoomsIds,
OnListFragmentInteractionListener listener, Context mContext) {
mValues = items;
mListener = listener;
this.favRoomsIds = favRoomsIds;
this.mContext = mContext;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_rooms_list_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
holder.imgPager.setAdapter(new ImageAdapter(mContext, holder.mItem.property.pictures));
holder.pageIndicatorView.setCount(holder.mItem.property.pictures.size());
holder.pageIndicatorView.setSelection(0);
holder.imgPager.addOnPageChangeListener(getPageChangeListener(holder));
holder.name.setText(holder.mItem.property.name);
holder.location.setText(holder.mItem.property.address.city);
holder.price.setText(MessageFormat.format("{0} € C.C", holder.mItem.property.price));
holder.tv1.setText(MessageFormat.format("{0}p", holder.mItem.property.personCount));
holder.tv2.setText(MessageFormat.format("{0}ch", holder.mItem.property.pieces));
holder.tv3.setText(MessageFormat.format("{0}m²", holder.mItem.property.surface));
holder.favToggle.setChecked(favRoomsIds.contains(holder.mItem.property.id));
holder.favToggle.setOnCheckedChangeListener((buttonView, isChecked) ->
toggleFavorite(holder.mItem.property.id, isChecked));
holder.mView.setOnClickListener(v -> {
if (null != mListener) {
mListener.onListFragmentInteraction(holder.mItem, favRoomsIds.contains(holder.mItem.property.id));
}
});
}
#Override
public int getItemCount() {
return mValues.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
final View mView;
Room mItem;
ViewPager imgPager;
TextView name, location, price, tv1, tv2, tv3;
ToggleButton favToggle;
PageIndicatorView pageIndicatorView;
ViewHolder(View view) {
super(view);
mView = view;
imgPager = view.findViewById(R.id.viewpager);
name = view.findViewById(R.id.name);
location = view.findViewById(R.id.location);
price = view.findViewById(R.id.price);
tv1 = view.findViewById(R.id.tv1);
tv2 = view.findViewById(R.id.tv2);
tv3 = view.findViewById(R.id.tv3);
favToggle = view.findViewById(R.id.favoritesToggleButton);
pageIndicatorView = view.findViewById(R.id.pageIndicatorView);
}
#Override
public String toString() {
return super.toString() + " '" + "'";
}
}
private void toggleFavorite(String propertyId, boolean fav) {
if (fav)
favRoomsIds.add(propertyId);
else
favRoomsIds.remove(propertyId);
JsonObjectRequest request = NetworkUtils.toggleRoomFavoritesRequest(
mContext, propertyId, fav, this::handleResponse, this::handleError);
VolleySingleton.getInstance(mContext).addToRequestQueue(request);
}
private void handleResponse(JSONObject response) {
Log.d("RoomFav.Response", response.toString());
}
private void handleError(VolleyError error) {
}
public void clear() {
mValues.clear();
notifyDataSetChanged();
}
public void addItems(List<Room> rooms) {
mValues.addAll(rooms);
notifyDataSetChanged();
}
private ViewPager.OnPageChangeListener getPageChangeListener(ViewHolder holder) {
return new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
holder.pageIndicatorView.setSelected(position);
}
#Override
public void onPageScrollStateChanged(int state) {
}
};
}
}
pager adapter
public class ImageAdapter extends PagerAdapter {
private Context mContext;
private List<String> mItems;
public ImageAdapter(Context context, List<String> items) {
mContext = context;
mItems = items;
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
ImageView img = (ImageView) inflater.inflate(R.layout.layout_image, collection, false);
String url = mItems.get(position);
if (!TextUtils.isEmpty(url))
Picasso.get().load(ApiPaths.IMG_PATH_PREFIX + url).into(img);
collection.addView(img);
return img;
}
#Override
public void destroyItem(#NonNull ViewGroup collection, int position, #NonNull Object view) {
collection.removeView((View) view);
}
#Override
public int getCount() {
return mItems.size();
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object object) {
return view == object;
}
}
pager item
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/img"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:clickable="false"/>

Expanding Listview using Recyclerview inside Scrollview

I tried below code to implement an expend and collapse content using recyclerview(listview) a link
final boolean isExpanded = position==mExpandedPosition;
holder.details.setVisibility(isExpanded?View.VISIBLE:View.GONE);
holder.itemView.setActivated(isExpanded);
if (isExpanded)
previousExpandedPosition = position;
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
notifyItemChanged(previousExpandedPosition);
notifyItemChanged(position);
}
});
In my case when i click the particular position in recyclerview its expanding but it goes above the recyclerview.I cant see the full expanded content.i can see only partial content.In this case i need to scroll the recyclerview to view the full content.But i am searching for a solution to view the content without scroll the recyclerview. If i click another position in recyclerview that should be placed over an recyclerview.
Hear is My Code
public class CommonFragment extends Fragment {
#BindView(R.id.news_lists)
RecyclerView news_lists;
#BindView(R.id.nested_scroll)
NestedScrollView nested_scroll;
ArrayList<String> Names;
ArrayList<String> responseProducts = null;
NewsListAdaspters mAdapter;
Context mContext;
String position_name;
public CommonFragment() {
}
public static CommonFragment getInstance(String position, ArrayList<String> response) {
CommonFragment fragmentDummy = new CommonFragment();
Bundle args = new Bundle();
args.putStringArrayList("Types", response);
args.putString("position", position);
fragmentDummy.setArguments(args);
return fragmentDummy;
}
#Override
public void setArguments(Bundle args) {
super.setArguments(args);
this.responseProducts = args.getStringArrayList("Types");
this.position_name = args.getString("position");
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
View view;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
try {
view = inflater.inflate(R.layout.fragment_common, container, false);
ButterKnife.bind(this, view);
} catch (InflateException ignored) {
}
mContext = getActivity();
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
news_lists.setLayoutManager(mLayoutManager);
news_lists.setNestedScrollingEnabled(false);
Names = new ArrayList<>();
Names.clear();
for (int i = 0; i < 15; i++) {
Names.add("News Details " + i);
}
Log.e("position_name==>", "" + position_name);
getList();
return view;
}
private void getList() {
if (responseProducts.size() > 0) {
mAdapter = new NewsListAdaspters(mContext, responseProducts, position_name);
news_lists.setAdapter(mAdapter);
}
}
public class NewsListAdaspters extends RecyclerView.Adapter<NewsListAdaspters.MyViewHolder> {
private ArrayList<String> data;
private Context context;
private String name;
int mExpandedPosition = -1;
int previousExpandedPosition = -1;
NewsListAdaspters(Context context, ArrayList<String> maps, String selectedFragmentName) {
this.context = context;
this.data = maps;
this.name = selectedFragmentName;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.common_view, parent, false);
final MyViewHolder holder = new MyViewHolder(itemView);
return holder;
}
#Override
public void onBindViewHolder(#NonNull final MyViewHolder holder, #SuppressLint("RecyclerView") final int position) {
holder.news_description.setText(data.get(position));
holder.news_title.setText(name);
final boolean isExpanded = position == mExpandedPosition;
Log.e("isExpanded=====>", "" + isExpanded);
holder.expend_layout.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
holder.itemView.setActivated(isExpanded);
if (isExpanded)
previousExpandedPosition = position;
holder.news_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, Activity_NewsFullDetails.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
holder.expand_click_layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1 : position;
notifyItemChanged(previousExpandedPosition);
notifyItemChanged(position);
}
});
holder.share_fb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "WORKING!!!!", Toast.LENGTH_SHORT).show();
}
});
holder.share_whatsapp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "WORKING!!!!", Toast.LENGTH_SHORT).show();
}
});
holder.share_twet.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "WORKING!!!!", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getItemCount() {
return data.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
#BindView(R.id.news_title)
public TextView news_title;
#BindView(R.id.news_hour)
public TextView news_hour;
#BindView(R.id.news_description)
public TextView news_description;
#BindView(R.id.news_image)
public ImageView news_image;
#BindView(R.id.expand_click_layout)
RelativeLayout expand_click_layout;
#BindView(R.id.expend_layout)
public LinearLayout expend_layout;
#BindView(R.id.full_title)
public TextView full_title;
#BindView(R.id.txt_description)
public TextView txt_description;
#BindView(R.id.share_twet)
public ImageView share_twet;
#BindView(R.id.share_whatsapp)
public ImageView share_whatsapp;
#BindView(R.id.share_fb)
public ImageView share_fb;
MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}
}
XML file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#03000000">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.RecyclerView
android:id="#+id/news_lists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
ITEM XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:animateLayoutChanges="true"
android:background="#drawable/comment_background"
android:stateListAnimator="#animator/comment_selection"
android:elevation="3dp"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/news_image"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_margin="2dp"
android:background="#drawable/icon_card"
android:scaleType="fitXY" />
<RelativeLayout
android:id="#+id/expand_click_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/news_image"
android:layout_alignTop="#+id/news_image"
android:layout_toEndOf="#+id/news_image"
android:layout_toRightOf="#+id/news_image">
<TextView
android:id="#+id/news_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_layout"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:maxEms="3"
android:maxLines="4"
android:padding="4dp"
android:text=""
android:textColor="#color/black_color"
android:textSize="18sp" />
<RelativeLayout
android:id="#+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_margin="4dp">
<TextView
android:id="#+id/news_hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/center_text"
android:layout_toStartOf="#+id/center_text"
android:maxLines="2"
android:text="Hours"
android:textColor="#color/black_color"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/center_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/news_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/center_text"
android:layout_toRightOf="#+id/center_text"
android:gravity="end"
android:text="News Title"
android:textColor="#color/black_color"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/expend_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/news_image"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/full_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Title Text"
android:textColor="#color/black_color"
android:textSize="20sp" />
<TextView
android:id="#+id/txt_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="#string/large_text1"
android:textColor="#color/black_color"
android:textSize="18sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal">
<ImageView
android:id="#+id/share_fb"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/share_facebook" />
<ImageView
android:id="#+id/share_whatsapp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/share_whatsapp" />
<ImageView
android:id="#+id/share_twet"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/share_tweet" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Try to use NestedScrollView instead of ScrollView and set below to your activity :-
recyclerView.setNestedScrollingEnabled(false);
For more information you can refer below stackoverflow links:-
How to use RecyclerView inside NestedScrollView?
Recyclerview inside ScrollView not scrolling smoothly

Android Custom Spinner unable to select an option and show it

I have a problem with spinner it do not let me select one item. I tried a lot of things and that still not working.
The picture shows that the spinner is in blank when the activity load
When I clicked the arrow it shows the items
but when I choose one, nothing happends.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.Inspeccion.DatosGeneralesActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
>
<TextView
android:id="#+id/tvSubestacionTitulo"
android:layout_below="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/strSubestacion"
android:textSize="18sp"
android:textColor="#color/colorPrimaryDark"
android:textStyle="bold"
/>
<TextView
android:id="#+id/tvSubestacionDato"
android:layout_below="#+id/tvSubestacionTitulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="Prueba"
/>
<Spinner
android:id="#+id/spinnerSubEstacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvSubestacionDato"
>
</Spinner>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
This is the Layout of the activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvNumeroOpcion"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:text="1"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/tvDescriptionOption"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:text="Guatemala"
android:textColor="#color/black"
android:textSize="14sp" />
</LinearLayout>
That is the custom layout for the spinner
Public class ComboAdapter extends BaseAdapter{
private List<Combo> combos;
private Activity activity;
private LayoutInflater inflater;
public ComboAdapter(List<Combo> combos, Activity activity) {
this.combos = combos;
this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return combos.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) {
View view = convertView;
if (convertView == null){
view = inflater.inflate(R.layout.combo_list_item, null);
TextView tvId = (TextView) view.findViewById(R.id.tvNumeroOpcion);
TextView tvDescripcion = (TextView) view.findViewById(R.id.tvDescriptionOption);
tvId.setText(combos.get(position).getId());
tvDescripcion.setText(combos.get(position).getDescripcion());
}
return view;
}
#Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getView(position, convertView,parent);
}
}
That is my Adapter
And below is my activity.
public class DatosGeneralesActivity extends AppCompatActivity {
private TextView tvSubestacionDato;
private List<Combo> listaCombo;
private Spinner spinnerSubestacion;
private ArrayAdapter<Combo> adapterSubestacion;
String seleccion;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_datos_generales);
//Inicializando textos
tvSubestacionDato = (TextView) findViewById(R.id.tvSubestacionDato);
//Inicializanco listas
listaCombo = new ArrayList<>();
//Inivializando spinners
spinnerSubestacion = (Spinner) findViewById(R.id.spinnerSubEstacion);
AppService service = API.getCombos().create(AppService.class);
Call<List<Combo>> subestacionCall = service.getSubestacion();
subestacionCall.enqueue(new Callback<List<Combo>>() {
#Override
public void onResponse(Call<List<Combo>> call, Response<List<Combo>> response) {
listaCombo.clear();
listaCombo.addAll(response.body());
}
#Override
public void onFailure(Call<List<Combo>> call, Throwable t) {
}
});
//final ComboAdapter adapter = new ComboAdapter(listaCombo, DatosGeneralesActivity.this);
final ArrayAdapter<Combo> adapter = new ArrayAdapter<Combo>(this, R.layout.support_simple_spinner_dropdown_item, listaCombo);
spinnerSubestacion.setAdapter(adapter);
spinnerSubestacion.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
adapter.notifyDataSetChanged();
Toast.makeText(DatosGeneralesActivity.this, ""+position, Toast.LENGTH_SHORT).show();
tvSubestacionDato.setText(listaCombo.get(position).getDescripcion());
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Try this changes:
Call adapter like:
ComboAdapter adapter = new ComboAdapter(DatosGeneralesActivity.this,
R.layout.combo_list_item, R.id.tvDescriptionOption, listaCombo);
now in adapter class:
public ComboAdapter(Activity context,int resouceId, int textviewId, List<Combo> list){
super(context,resouceId,textviewId, list);
this.combos = list;
this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
Also inside your getView() method inflate layout like:
if (convertView == null){
view = inflater.inflate(R.layout.combo_list_item, parent , false);

GridView onClickListener/onItemClickListener not working

I am trying to implement a Card view inside grid view. The grid view is showing perfectly; even when I touch on a grid view item it's showing nothing. But when I click on the text which is display below its work. I referred This but not working...
Thanks.
My code is as below,
// Contact_Backup.java
public class Contact_Backup extends AppCompatActivity {
#Bind(R.id.gridview)
GridView gridview;
String[] contact_screen_array;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_backup);
ButterKnife.bind(this);
contact_screen_array = getResources().getStringArray(R.array.TextScreen);
String[] contact_icon_array = getResources().getStringArray(R.array.IconScreen);
String concat = "\nContacts";
gridview.setAdapter(new Custom_Adapter(getApplicationContext(),contact_icon_array,contact_screen_array,concat));
}
}
//Custom_Adapter
public class Custom_Adapter extends BaseAdapter {
Context contaxt;
String[] Array_text;
String[] Array_icon;
String concat;
LayoutInflater inflater;
public Custom_Adapter(Context context,String[] Array_icon, String[] Array_text, String concat)
{
this.contaxt = context;
this.Array_text = Array_text;
this.Array_icon = Array_icon;
this.concat=concat;
inflater = (LayoutInflater)context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return Array_text.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Bind(R.id.Screen_icon)
Button Screen_icon;
#Bind(R.id.Screen_text)
TextView Screen_text;
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View grid;
LayoutInflater inflater = (LayoutInflater) contaxt
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(contaxt);
grid = inflater.inflate(R.layout.new_app_card_layout, null);
ButterKnife.bind(this, grid);
Screen_text.setText(Array_text[position]+concat);
Screen_icon.setText(Array_icon[position]);
Typeface font = Typeface.createFromAsset(contaxt.getAssets(), "fonts/fontawesome-webfont.ttf" );
Screen_icon.setTypeface(font);
} else {
grid = (View) convertView;
}
grid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("TAG::",""+position);
}
});
return grid;
}
}
// contact_backup.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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/main_backgorund"
>
<RelativeLayout
android:background="#color/transparent"
android:padding="5.0dip"
android:id="#+id/top_bar_screen"
android:layout_weight="0.2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/newclr"
android:id="#+id/tvContacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contacts"
android:shadowColor="#000000"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="2.0"
android:layout_centerVertical="true" />
<TextView
android:textColor="#color/newclr"
android:id="#+id/tvLastBackup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/last_backup"
android:shadowColor="#000000"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="2.0"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="#+id/v1"
android:layout_below="#+id/top_bar_screen"
android:background="#color/newclr"/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipe"
android:layout_below="#+id/v1"
android:paddingTop="20sp"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:layout_weight="0.6"
>
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:layout_height="wrap_content" />
</GridLayout>
<!-- com.startapp.android.publish.banner.Banner
android:id="#+id/startAppBanner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="0.2"
android:layout_centerHorizontal="true" /-->
</RelativeLayout>
// new_app_card_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/fssr_card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
card_view:cardBackgroundColor="#color/transparent"
>
<LinearLayout
android:gravity="center"
android:orientation="vertical"
android:id="#+id/Contacts_Button_Layout"
android:background="#drawable/linearlayout_normal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="-1.0dip"
android:layout_weight="1.0"
>
<Button
android:textSize="35.0sp"
android:textColor="#color/newclr"
android:layout_gravity="center"
android:id="#+id/Screen_icon"
android:background="#null"
android:padding="20sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/fa_icon_contact"
android:drawablePadding="5.0dip"
android:textAllCaps="false" />
<TextView
android:textSize="15.0sp"
android:textColor="#color/white"
android:layout_gravity="center"
android:textAlignment="center"
android:id="#+id/Screen_text"
android:background="#color/newclr"
android:padding="5sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/contactsbackup"
android:textAllCaps="false"/>
</LinearLayout>
</android.support.v7.widget.CardView>
use this method for clicking on a gridview item:
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// your action when gridView item is clicked
}
});
Set the listener on the actual gridview object.
gridView.setOnItemClickListener(new OnItemClickListener()...);
Try this,
public class Contact_Backup extends AppCompatActivity {
#Bind(R.id.gridview)
GridView gridview;
String[] contact_screen_array;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_backup);
ButterKnife.bind(this);
contact_screen_array = getResources().getStringArray(R.array.TextScreen);
String[] contact_icon_array = getResources().getStringArray(R.array.IconScreen);
String concat = "\nContacts";
gridview.setAdapter(new Custom_Adapter(getApplicationContext(),contact_icon_array,contact_screen_array,concat));
gridview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
for(int i=0;i<contact_screen_array.length;i++) {
Log.d("TAG::", "Position"+contact_screen_array[i]);
}
}
});
}
}
Finally, I succeed. here is the code.
Just use Textview instead of Button in // new_app_card_layout.xml.
Just Update it,
<TextView
android:textSize="35.0sp"
android:textColor="#color/newclr"
android:layout_gravity="center"
android:id="#+id/Screen_icon"
android:background="#null"
android:padding="20sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/fa_icon_contact"
android:drawablePadding="5.0dip"
android:textAllCaps="false"
android:textAlignment="center" />
Thank You so much, All of you for help... :)
Try this i have updated your custom Adapter class.please check again with this updated code.
public class Custom_Adapter extends BaseAdapter {
Context contaxt;
String[] Array_text;
String[] Array_icon;
String concat;
LayoutInflater inflater;
public Custom_Adapter(Context context,String[] Array_icon, String[] Array_text, String concat)
{
this.contaxt = context;
this.Array_text = Array_text;
this.Array_icon = Array_icon;
this.concat=concat;
inflater = (LayoutInflater)context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return Array_text.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Bind(R.id.Screen_icon)
Button Screen_icon;
#Bind(R.id.Screen_text)
TextView Screen_text;
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View grid;
LayoutInflater inflater = (LayoutInflater) contaxt
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(contaxt);
grid = inflater.inflate(R.layout.new_app_card_layout, null);
ButterKnife.bind(this, grid);
Screen_text.setText(Array_text[position]+concat);
Screen_icon.setText(Array_icon[position]);
Typeface font = Typeface.createFromAsset(contaxt.getAssets(), "fonts/fontawesome-webfont.ttf" );
Screen_icon.setTypeface(font);
grid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("TAG::",""+position);
}
});
} else {
grid = (View) convertView;
grid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("TAG::",""+position);
}
});
}
return grid;
}
}
Hope this helps you out !

Categories

Resources