I want to show my custom ArrayAdapter in a ListFragment with a SlidingTabLayout. Previously I tested the adapter in a normal activity and worked fine, also the SlidingTabLayout worked correctly, but yet the ListFragment show nothing. I get the data from a meteor server and logcat show me the data has been downloaded...
Does anybody have some tips?
This is my Fragment Java Code:
public class MorningFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_morning,container,false);
return v;
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
MedicationTimeAdapter timeAdapter;
timeAdapter = new MedicationTimeAdapter(getActivity(), R.layout.item_time);
setListAdapter(timeAdapter);
}
}
And my Fragment XML Code:
<?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">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
My adapter
public class MedicationTimeAdapter extends ArrayAdapter<MedicationTime> implements DataManager.MedicationCallback {
private static final String LOG_TAG = MedicationTimeAdapter.class.getName();
private final int resourceId;
private final Activity activity;
// private List<MedicationEntry> medications = new ArrayList<MedicationEntry>();
public MedicationTimeAdapter(Activity context, int resource) {
super(context, resource);
resourceId = resource;
activity = context;
}
#Override
public void handleMedicationPlan(List<MedicationEntry> medication) {
// ignore
}
#Override
public void handleMedicationTimes(final List<MedicationTime> medicationTimes) {
// TODO Activity möglicherweise nicht mehr aktiv
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
setItems(medicationTimes);
}
});
}
public void setItems(List<MedicationTime> itemList) {
clear();
for (MedicationTime item : itemList) {
add(item);
}
notifyDataSetChanged();
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public View getView(int index, View convertView, ViewGroup parent) {
//data from your adapter
MedicationTime itemData = getItem(index);
if (convertView == null) {
// final LayoutInflater inflater = MHApplication.getLayoutInflater();
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
// TODO mit Referenz Parent-Group erzeugen?! (war für ColorFinder notwendig, um die LayoutParams beim Laden zu erhalten)
// convertView = inflater.inflate(resourceId, parent, false);
convertView = inflater.inflate(resourceId, null);
// prepareInflatedView(convertView);
}
setViewContent(index, convertView, itemData);
return convertView;
}
protected void setViewContent(int index, View itemView, MedicationTime itemData) {
final TextView nameView = (TextView) itemView.findViewById(R.id.time_name);
final TextView medicationView = (TextView) itemView.findViewById(R.id.medication);
int nameId = activity.getResources().getIdentifier("time_name." + itemData.getTimeName(), "string", activity.getPackageName());
nameView.setText(activity.getResources().getString(nameId));
nameView.setText(nameId);
StringBuilder medText = new StringBuilder();
List<MedicationTime.Entry> medications = itemData.getMedications();
for (MedicationTime.Entry medication : medications) {
medText.append(medication.getCount());
medText.append(" * ");
medText.append(medication.getMedicationEntry().getSubstance());
medText.append(" (");
medText.append(medication.getMedicationEntry().getTradingName());
medText.append(")\n");
}
medicationView.setText(medText.toString());
}
Edit:
I solved the Problem , i have a Method in my mainActivity to fill the adapter with Data. The problem was i create a new Adapter in my Fragment. So i add a konstruktor in my Fragment class and submitter the Adapter from my mainActivity.
public MorningFragment(MedicationTimeAdapter timeAdapter) {
medicationTimeAdapter = timeAdapter;
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_morning,container,false);
setListAdapter(medicationTimeAdapter);
return v;
}
Call handleMedicationTimes(final List<MedicationTime> medicationTimes) with some data, Your code seems is not inflating any data.
Related
I want to create tags using RecyclerView that can be selected to produce results.
What I want to achieve is when I tap on Books TextView on the top-right must change to Books immediately. In my case when I tap on Books it just stays in Art and it replaces Art with Books only when I replace my fragments. I also highlight buttons when clicked (changing border from grey to black) but after changing fragments highlights return back to Art again. Shortly I want to highlight button when clicked and change TextView content based on clicked button text. I partly achieved it by using interfacews but didn't get what I wanted. I provided codes below:
TrendCategoryTagsAdapter.java:
public class TrendCategoryTagsAdapter extends FirestoreRecyclerAdapter<CategorySelection, TrendCategoryTagsAdapter.TrendCategoryTagsHolder> {
Context context;
onCategoryTagClicked onCategoryTagClicked;
int row_index;
public TrendCategoryTagsAdapter(#NonNull FirestoreRecyclerOptions<CategorySelection> options, Context context, com.rajabmammadli.paragrafredesign.Interface.onCategoryTagClicked onCategoryTagClicked) {
super(options);
this.context = context;
this.onCategoryTagClicked = onCategoryTagClicked;
}
#Override
protected void onBindViewHolder(#NonNull final TrendCategoryTagsHolder holder, final int position, #NonNull CategorySelection model) {
holder.categoryNameText.setText(model.getCategoryName());
holder.categoryNameContainer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
row_index = position;
notifyDataSetChanged();
}
});
if (row_index == position) {
holder.categoryNameContainer.setBackground(ContextCompat.getDrawable(context, R.drawable.black_rounded_bg));
onCategoryTagClicked.onTagClick(holder.categoryNameText.getText().toString());
} else {
holder.categoryNameContainer.setBackground(ContextCompat.getDrawable(context, R.drawable.grey_rounded_bg));
}
}
#NonNull
#Override
public TrendCategoryTagsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.trendcategory_cell, parent, false);
return new TrendCategoryTagsAdapter.TrendCategoryTagsHolder(v);
}
public static class TrendCategoryTagsHolder extends RecyclerView.ViewHolder {
RelativeLayout categoryNameContainer;
TextView categoryNameText;
public TrendCategoryTagsHolder(#NonNull View itemView) {
super(itemView);
categoryNameContainer = itemView.findViewById(R.id.categoryNameContainer);
categoryNameText = itemView.findViewById(R.id.categoryNameText);
}
}
}
trendcategory_cell.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<RelativeLayout
android:id="#+id/categoryNameContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/grey_rounded_bg">
<TextView
android:id="#+id/categoryNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/gilroyregular"
android:padding="15dp"
android:text="categoryname"
android:textColor="#android:color/black" />
</RelativeLayout>
</RelativeLayout>
TrendingFragment.java:
public class TrendingFragment extends Fragment implements onCategoryTagClicked {
RecyclerView trendingCategoryRV;
TextView noPostTV, selectedCategoryText;
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference categoryRef;
String selectedCategory = "Art";
TrendCategoryTagsAdapter trendCategoryTagsAdapter;
public TrendingFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_trending, container, false);
trendPostRV = view.findViewById(R.id.trendPostRV);
trendingCategoryRV = view.findViewById(R.id.trendingCategoryRV);
noPostTV = view.findViewById(R.id.noPostTV);
selectedCategoryText = view.findViewById(R.id.selectedCategoryText);
selectedCategoryText.setText(selectedCategory);
setUpTrendCategoryTagsRV();
setUpTrendingPostRV();
// Inflate the layout for this fragment
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
trendCategoryTagsAdapter.startListening();
}
#Override
public void onDestroyView() {
super.onDestroyView();
trendCategoryTagsAdapter.stopListening();
}
private void setUpTrendCategoryTagsRV() {
categoryRef = db.collection("Categories");
Query query = categoryRef.orderBy("categoryName", Query.Direction.ASCENDING);
FirestoreRecyclerOptions<CategorySelection> options = new FirestoreRecyclerOptions.Builder<CategorySelection>()
.setQuery(query, CategorySelection.class)
.build();
trendCategoryTagsAdapter = new TrendCategoryTagsAdapter(options, getContext(), this);
trendingCategoryRV.setNestedScrollingEnabled(false);
final LinearLayoutManager trendingTagsLM = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
trendingCategoryRV.setLayoutManager(trendingTagsLM);
trendingCategoryRV.setAdapter(trendCategoryTagsAdapter);
trendCategoryTagsAdapter.notifyDataSetChanged();
}
#Override
public void onTagClick(String categoryName) {
selectedCategory = categoryName;
}
}
Any help will be appreciated. Thanks in advance
Please, help to figure out why view binding onItemClickListener doesn't work.
To be short: I'm loading list of fragments. And need to choose fragment to load by clicking to item, so I implemented AdapterView.OnItemClickListener for this purpose. But when I perform a click - nothing happens, method does't called.
public class ChooserFragment extends ListFragment implements AdapterView.OnItemClickListener {
private ChooserFragmentBinding mBinding;
private static final Class<?>[] CLASSES = new Class[]{
EmailPasswordFragment.class,
EmailPasswordFragment.class,
};
private static final int[] DESCRIPTION_IDS = new int[]{
R.string.desc_emailpassword,
R.string.desc_emailpassword,
};
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
mBinding = ChooserFragmentBinding.inflate(inflater, container, false);
View view = mBinding.getRoot();
CustomArrayAdapter adapter = new CustomArrayAdapter(getContext(), android.R.layout.simple_list_item_2, CLASSES);
adapter.setDescriptionIds(DESCRIPTION_IDS);
mBinding.list.setAdapter(adapter);
mBinding.list.setOnItemClickListener(this);
return view;
}
#Override
public void onDestroyView() {
super.onDestroyView();
mBinding = null;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Class<?> clicked = CLASSES[position];
Log.d("Clicked", String.valueOf(position));
}
public static class CustomArrayAdapter extends ArrayAdapter<Class<?>> {
private Context mContext;
private int[] mDescriptionIds;
public CustomArrayAdapter(Context context, int resource, Class[] objects) {
super(context, resource, objects);
mContext = context;
}
#SuppressWarnings("NullableProblems")
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(android.R.layout.simple_list_item_1, null);
}
((TextView) view.findViewById(android.R.id.text1)).setText(mDescriptionIds[position]);
return view;
}
public void setDescriptionIds(int[] descriptionIds) {
mDescriptionIds = descriptionIds;
}
}
}
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
Thanks.
Is there some reason you have to have the Fragment extend ListFragment and implement AdapterView.OnItemClickListener? Try it the normal way and see what happens:
mBinding.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("LOG", "test");
}
});
When I click the listview in tab Fragment 1 it won't work jump into next activities. I already setOnItemClickListener in the class, but still won't work. Now my problem is when I click the listview it won't work.
public class TabFragment1_Staff extends Fragment {
ListView lsReport;
ArrayList<HashMap<String, String>> reportlist;
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.activity_tab_fragment1__staff, container, false);
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
reportlist = new ArrayList<>();
lsReport = getActivity().findViewById(R.id.listReport);
loadReport();
lsReport.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(),AddStatusDialogWindow.class);
Bundle bundle = new Bundle();
Log.e("HANIS",reportlist.get(position).get("reportID"));
bundle.putString("reportID",reportlist.get(position).get("reportID"));
bundle.putString("fullName",reportlist.get(position).get("fullName"));
bundle.putString("icNum",reportlist.get(position).get("icNum"));
bundle.putString("phoneNum",reportlist.get(position).get("phoneNum"));
bundle.putString("Rdate",reportlist.get(position).get("Rdate"));
bundle.putString("Rtime",reportlist.get(position).get("Rtime"));
bundle.putString("timeName",reportlist.get(position).get("timeName"));
bundle.putString("typeVehicle",reportlist.get(position).get("typeVehicle"));
bundle.putString("registrationnum",reportlist.get(position).get("registrationnum"));
bundle.putString("location",reportlist.get(position).get("location"));
bundle.putString("brief",reportlist.get(position).get("brief"));
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
tabFragment1.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listReport"
android:layout_width="match_parent"
android:layout_height="300dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
</ScrollView>
LoadReport class
class LoadReport extends AsyncTask<Void, Void, String> {
#Override
protected String doInBackground(Void... params) {
// Perform api call
}
#Override
protected void onPostExecute(String s) {
reportlist.clear();
// Parse api response and fill in reportlist var
ListAdapter adapter = new CustomList_StatusReport(
getActivity(), reportlist,
R.layout.activity_custom_list__status_report, new String[]
{"reportID","fullName","icNum","phoneNum"}, new int[]
{R.id.tvReport_ID,R.id.tvCompliantName,R.id.tvCompliantIC,R.id.tvCompliantPhone});
lsReport.setAdapter(adapter);
Toast.LENGTH_SHORT).show();
}
}
LoadReport loadReport = new LoadReport();
loadReport.execute();
}
public class CustomList_StatusReport extends SimpleAdapter {
private Context mContext;
public LayoutInflater inflater = null;
public CustomList_StatusReport(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
mContext = context;
inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
try {
if (convertView == null)
vi = inflater.inflate(R.layout.activity_custom_list__status_report, null);
HashMap<String, Object> data = (HashMap<String, Object>) getItem(position);
TextView reportID = vi.findViewById(R.id.tvReport_ID);
TextView cName = vi.findViewById(R.id.tvCompliantName);
TextView cIC = vi.findViewById(R.id.tvCompliantIC);
TextView cPhone = vi.findViewById(R.id.tvCompliantPhone);
String id = (String) data.get("reportID");
String name = (String)data.get("fullName");
String ic = (String)data.get("icNum");
String phone = (String)data.get("phoneNum");
reportID.setText(id);
cName.setText(name);
cIC.setText(ic);
cPhone.setText(phone);
}catch (IndexOutOfBoundsException e){}
return vi;
}
In tabFragment1.xml, why you are using the below lines code?
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
Please remove these if not needed and let us know whether this issue exists?
I want to use custom ListView in extends from ListFragment class. After create new subClass extends from BaseAdapter into current class and set layout to that I get ... has stopped error.
list_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"/>
</LinearLayout>
ResivedSMS.java :
public class ResivedSMS extends ListFragment {
private String testArray1[];
private String testArray2[];
private ListView listFragment;
public ResivedSMS() {
testArray1 = new String[] {
"1111111111",
"2222222222",
"3333333333",
"4444444444",
"5555555555",
"6666666666",
};
testArray1 = new String[] {
"AAAAA",
"BBBBB",
"CCCCC",
"DDDDD",
"FFFFF",
"GGGGG",
};
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
listFragment = (ListView) inflater.inflate(
R.layout.list_fragment, container, false);
ViewResivedSMSDetailes customListView = new ViewResivedSMSDetailes(getActivity(),testArray1,testArray2);
listFragment.
setAdapter( customListView );
return listFragment;
}
#Override
public void onListItemClick(ListView list, View v, int position, long id) {
Toast.makeText(getActivity(), getListView().getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
}
class ViewResivedSMSDetailes extends BaseAdapter
{
private LayoutInflater inflater;
private String[] values1;
private String[] values2;
private class ViewHolder {
TextView txt1;
TextView txt2;
}
public ViewResivedSMSDetailes(Context context,String[] values1,String[] values2)
{
this.values1=values1;
this.values2=values2;
inflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return values1.length;
}
#Override
public Object getItem(int index) {
return values1[index];
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder = null;
if(convertView ==null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_fragment, null);
holder.txt1 = (TextView)convertView.findViewById(R.id.txt1);
holder.txt2 = (TextView)convertView.findViewById(R.id.txt2);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
holder.txt1.setText(values1[position]);
holder.txt2.setText(values2[position]);
return convertView;
}
}
}
logcat Result:
08-24 10:33:34.675 349-349/ir.tsms E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.LinearLayout
at ir.tsms.ResivedSMS.onCreateView(ResivedSMS.java:50)
ResivedSMS.java:50 is:
listFragment = (ListView) inflater.inflate(
R.layout.list_fragment, container, false);
Whats my code problem and how to resolved Thanks?
problem:
inflater.inflate(R.layout.list_fragment, container, false);
You are inflating a LinearLayout not a ListView thus giving you ClassCastException
solution:
Since you are using ListFragment you can directly set the adapter, since ListFragment has its own default ListView. Set the adapter in the onCreate Method.
sample:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewResivedSMSDetailes customListView = new ViewResivedSMSDetailes(getActivity(),testArray1,testArray2);
setListAdapter( customListView ); //call the method if listFragment
}
I have been trying this code for extracting data from Parse.com, it works great with GridView and ListView. What i want to do is, implement it in a HorizontalListView, for which i use this library. The main issue with this is, the images are loading properly but the list wont scroll at all, where as if i use it normally for anything else, it works fine. I have tried it with loading images from URL's.
ParseFragment.java
public class ParseFragment extends Fragment {
public ParseFragment() {
}
HorizontalListView grid;
List<ParseObject> ob;
GridViewAdapter adapter;
private List<GlowoodList> glowoodList = null;
View rootView;
String button_str;
ParseFile image;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_main, container, false);
Bundle bundle = getArguments();
button_str = bundle.getString("button");
Log.e("BUTTON CLICKED", "BUTTON CLICKED: " + button_str);
Thread t = new Thread(new Runnable() {
#Override
public void run() {
Parse.initialize(ParseFragment.this.getActivity(),
"Application_id",
"Client_id");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
new RemoteDataTask().execute();
}
});
t.start();
return rootView;
}
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... params) {
glowoodList = new ArrayList<GlowoodList>();
try {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
button_str);
query.orderByAscending("position");
ob = query.find();
for (ParseObject country : ob) {
image = (ParseFile) country.get("wallpapers");
GlowoodList map = new GlowoodList();
map.setPhone(image.getUrl());
map.setName((String) country.get("Name"));
glowoodList.add(map);
}
} catch (ParseException e) {
Log.e("ParseException", "parse: " + e);
}
return null;
}
#Override
protected void onPostExecute(Void result) {
grid = (HorizontalListView) rootView.findViewById(R.id.grid);
adapter = new GridViewAdapter(ParseFragment.this.getActivity(),
glowoodList);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.e("URL", "URL" + image.getUrl());
}
});
}
}
}
fragment_main.xml
<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="com.example.parsedotcom.MainActivity$PlaceholderFragment" >
<com.meetme.android.horizontallistview.HorizontalListView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawHorizontalTrack="true"
></com.meetme.android.horizontallistview.HorizontalListView>
</RelativeLayout>
GridViewAdapter.java
public class GridViewAdapter extends BaseAdapter {
Context context;
LayoutInflater inflater;
ImageLoader image;
private List<GlowoodList> glowoodList = null;
private ArrayList<GlowoodList> arraylist;
public GridViewAdapter(Context context, List<GlowoodList> glowoodList) {
super();
this.context = context;
this.glowoodList = glowoodList;
this.arraylist = new ArrayList<GlowoodList>();
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.arraylist.addAll(glowoodList);
image = new ImageLoader(context);
}
public class ViewHolder{
ImageView phone;
TextView text;
}
#Override
public int getCount() {
return glowoodList.size();
}
#Override
public Object getItem(int position) {
return glowoodList.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 = inflater.inflate(R.layout.grid_images, null);
holder.phone = (ImageView)convertView.findViewById(R.id.phone);
holder.text = (TextView)convertView.findViewById(R.id.text);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
image.DisplayImage(glowoodList.get(position).getPhone(),holder.phone);
holder.text.setText(glowoodList.get(position).getName());
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("phone", glowoodList.get(position).getPhone());
bundle.putString("name", glowoodList.get(position).getName());
Log.e("BUNDLE POSITION", "BUNDLE POSITION:"+bundle);
}
});
return convertView;
}
}
Can someone please help??! The HorizontalListView does not scroll at all !!!
Thank you