Override default expandablelistview expand behaviour - android

How does one go about manually expanding and collapsing an expandablelistview? I know of expandGroup(), but am not sure where to set the onClickListener(), as half of this code, is in a separate library project.
ExpandableDeliveryList
package com.goosesys.dta_pta_test;
[imports removed to save space]
public class ExpandableDeliveryList<T> extends ExpandableListActivity {
private ArrayList<GooseDeliveryItem> parentItems = new ArrayList<GooseDeliveryItem>();
private ArrayList<DeliverySiteExtras> childItems = new ArrayList<DeliverySiteExtras>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// CREATE THE EXPANDABLE LIST AND SET PROPERTIES //
final ExpandableListView expandList = getExpandableListView();
expandList.setDividerHeight(0);
expandList.setGroupIndicator(null);
expandList.setClickable(false);
// LIST OF PARENTS //
setGroupParents();
// CHILDREN //
setChildData();
// CREATE ADAPTER //
GooseExpandableArrayAdapter<?> adapter = new GooseExpandableArrayAdapter<Object>(
R.layout.goose_delivery_item,
R.layout.goose_delivery_item_child,
parentItems,
childItems);
adapter.setInflater((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);
expandList.setAdapter(adapter);
expandList.setOnChildClickListener(this);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case android.R.id.home:
{
Intent intent = new Intent(this, Main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
}
default:
{
return super.onOptionsItemSelected(item);
}
}
}
public void setGroupParents()
{
DatabaseHelper dbHelper = new DatabaseHelper(this);
List<DeliverySite> sites = new ArrayList<DeliverySite>();
sites = dbHelper.getAllSites();
GooseDeliveryItem[] deliveries = new GooseDeliveryItem[sites.size()];
for(int i=0; i<sites.size(); i++)
{
Delivery del = new Delivery();
try
{
del = dbHelper.getDeliveryByJobNo(sites.get(i).id);
}
catch(Exception e)
{
e.printStackTrace();
}
final GooseDeliveryItem gdi;
if((Double.isNaN(sites.get(i).lat)) || (Double.isNaN(sites.get(i).lng)))
{
gdi = new GooseDeliveryItem(sites.get(i).id, sites.get(i).company);
}
else
{
gdi = new GooseDeliveryItem(sites.get(i).id, sites.get(i).company, sites.get(i).lat, sites.get(i).lng);
}
if(del.getReportedFully() == 1)
{
gdi.isReportedFully = true;
}
deliveries[i] = gdi;
}
// FINALLY ADD THESE ITEMS TO THE PARENT ITEMS LIST ARRAY //
for(GooseDeliveryItem g : deliveries)
parentItems.add(g);
}
public void setChildData()
{
//DatabaseHelper dbHelper = new DatabaseHelper(this);
ArrayList<DeliverySiteExtras> extras = new ArrayList<DeliverySiteExtras>();
for(int i=0; i<parentItems.size(); i++)
{
DeliverySiteExtras dse = new DeliverySiteExtras();
extras.add(dse);
}
childItems = extras;
}
}
ArrayAdapter
package com.goosesys.gooselib.Views;
[imports removed to save space]
public class GooseExpandableArrayAdapter<Object> extends BaseExpandableListAdapter
{
private Activity activity;
private ArrayList<DeliverySiteExtras> childItems;
private LayoutInflater inflater;
ArrayList<GooseDeliveryItem> parentItems;
private DeliverySiteExtras child;
private int layoutId;
private int childLayoutId;
public GooseExpandableArrayAdapter(int layoutId, int childLayoutId, ArrayList<GooseDeliveryItem> parents, ArrayList<DeliverySiteExtras> children)
{
this.layoutId = layoutId;
this.childLayoutId = childLayoutId;
this.parentItems = (ArrayList<GooseDeliveryItem>) parents;
this.childItems = (ArrayList<DeliverySiteExtras>)children;
}
public GooseExpandableArrayAdapter(ArrayList<GooseDeliveryItem> parents, ArrayList<DeliverySiteExtras> children, int layoutId)
{
this.parentItems = parents;
this.childItems = children;
this.layoutId = layoutId;
}
public void setInflater(LayoutInflater inflater, Activity activity)
{
this.inflater = inflater;
this.activity = activity;
}
#Override
public Object getChild(int arg0, int arg1)
{
return null;
}
#Override
public long getChildId(int arg0, int arg1)
{
return 0;
}
/*
* Child view get method
* Utilise this to edit view properties at run time
*/
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
child = childItems.get(groupPosition);
if(convertView == null)
{
convertView = inflater.inflate(this.childLayoutId, null);
}
// GET ALL THE OBJECT VIEWS AND SET THEM HERE //
setGeoLocation(groupPosition, convertView);
convertView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
}
});
return convertView;
}
#Override
public void onGroupCollapsed(int groupPosition)
{
super.onGroupCollapsed(groupPosition);
}
#Override
public void onGroupExpanded(int groupPosition)
{
super.onGroupExpanded(groupPosition);
}
#Override
public int getChildrenCount(int groupPosition)
{
return 1; //childItems.get(groupPosition);
}
#Override
public Object getGroup(int groupPosition)
{
return null;
}
#Override
public int getGroupCount()
{
return parentItems.size();
}
#Override
public long getGroupId(int arg0)
{
return 0;
}
/*
* Parent View Object get method
* Utilise this to edit view properties at run time.
*/
#Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
if(convertView == null)
{
convertView = inflater.inflate(this.layoutId, null);
}
// GET ALL OBJECT VIEWS AND SET THEM HERE -- PARENT VIEW //
TextView name = (TextView)convertView.findViewById(R.id.customerName);
name.setText(parentItems.get(groupPosition).customerText);
ImageView go = (ImageView)convertView.findViewById(R.id.moreDetails);
go.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent(activity, DeliveryJobActivity.class);
i.putExtra("obj", parentItems.get(groupPosition));
activity.startActivity(i);
}
});
return convertView;
}
#Override
public boolean hasStableIds()
{
return false;
}
#Override
public boolean isChildSelectable(int arg0, int arg1)
{
return false;
}
private void setGeoLocation(final int groupPosition, View parent)
{
GeoLocation geoLocation = new GeoLocation(activity);
final double lat = geoLocation.getLatitude();
final double lng = geoLocation.getLongitude();
// GET OUR START LOCATION //
Location startLocation = new Location("Start");
startLocation.setLatitude(lat);
startLocation.setLongitude(lng);
// GET OUR DESTINATION //
Location destination = new Location("End");
destination.setLatitude(((GooseDeliveryItem)parentItems.get(groupPosition)).latitude);
destination.setLongitude(((GooseDeliveryItem)parentItems.get(groupPosition)).longitude);
double distanceValue = startLocation.distanceTo(destination);
TextView tv = (TextView)parent.findViewById(R.id.extraHeader);
tv.setText(parentItems.get(groupPosition).customerText + " information:");
TextView ds = (TextView)parent.findViewById(R.id.deliveryDistance);
ds.setText("Distance (from location): " + String.valueOf(Math.ceil(distanceValue * GooseConsts.METERS_TO_A_MILE)) + " Mi (approx)");
ImageView img = (ImageView)parent.findViewById(R.id.directionsImage);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// invoke google maps with lat / lng position
Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?saddr="
+ (lat) + "," + (lng)
+ "&daddr="
+ ((GooseDeliveryItem)parentItems.get(groupPosition)).latitude + ","
+ ((GooseDeliveryItem)parentItems.get(groupPosition)).longitude
));
activity.startActivity(navigation);
}
});
}
}
Ideally, my bosses would like to have a "+" button, that when clicked expands the listview manually. Rather than clicking anywhere on the view and it doing it automatically. Is this possible? Also, setting setClickable(false) seems to have no effect. Because it'll still expand when any list item is clicked. Am I missing something there also?
Cheers.

You can add an ExpandableListView Group Click Listener ("ExpandableListView::setOnGroupClickListener") to monitor and suppress click event for the ListView Groups. Using your code example, this would be done in your "ExpandableDeliveryList" module after you create the ExpandableListView.
Then in your "+" (and "-") Button click handlers, you can add logic to expand/collapse some or all of the ListView Groups using the "ExpandableListView::expandGroup()" and "ExpandableListView::collapseGroup()" methods.
You do not need to return "false" from the overridden "isChildSelectable()" method as this has no effect on what you are trying to accomplish (and will prevent anyone from clicking/selecting child items in the ListView).
Code examples are shown below:
// CREATE THE EXPANDABLE LIST AND SET PROPERTIES //
final ExpandableListView expandList = getExpandableListView();
//...
expandList.setOnGroupClickListener(new android.widget.ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick( ExpandableListView parent,
View view,
int groupPosition,
long id) {
// some code...
// return "true" to consume the event (and prevent the Group from expanding/collapsing) / "false" to allow the Group to expand/collapse normally
return true;
}
});
To manually expand and collapse the ListView Groups:
// enumerate thru the ExpandableListView Groups
// [in this code example, a single index is used...]
int groupPosition = 0;
// expand the ListView Group/s
if (m_expandableListView.isGroupExpanded(groupPosition) == false) {
// API Level 14+ allows you to animate the Group expansion...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
m_expandableListView.expandGroup(groupPosition, true);
}
// else just expand the Group without animation
else {
m_expandableListView.expandGroup(groupPosition);
}
}
// collapse the ListView Group/s
else {
m_expandableListView.collapseGroup(groupPosition);
}
Hope this Helps.

Related

Highlight Header View of expandable list view if Its at least one Child View is highlighted on Android Studio

I want Header View on expandable List View is automatically changed background color right after initial program if there is at least one of Child View be highlighted
I get this program from http://tutorialscache.com/expandable-listview-android-tutorials/ as an example
Here is the ExpandableCustomAdapter Class
public class ExpandableCustomAdapter extends BaseExpandableListAdapter{
//Initializing variables
private List<String> headerData;
private HashMap<String, ArrayList<ChildDataModel>> childData;
private Context mContext;
private LayoutInflater layoutInflater;
// constructor
public ExpandableCustomAdapter(Context mContext, List<String> headerData,
HashMap<String, ArrayList<ChildDataModel>> childData) {
this.mContext = mContext;
this.headerData = headerData;
this.childData = childData;
this.layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getGroupCount() {
return this.headerData.size();
}
#Override
public int getChildrenCount(int headPosition) {
return this.childData.get(this.headerData.get(headPosition)).size();
}
#Override
public Object getGroup(int headPosition) {
return this.headerData.get(headPosition);
}
#Override
public Object getChild(int headPosition, int childPosition) {
return this.childData.get(this.headerData.get(headPosition))
.get(childPosition);
}
#Override
public long getGroupId(int headPosition) {
return headPosition;
}
#Override
public long getChildId(int headPosition, int childPosition) {
return this.childData.get(this.headerData.get(headPosition))
.get(childPosition).getId();
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int headPosition, boolean is_expanded, View view, ViewGroup headGroup) {
// Heading of each group
String heading = (String) getGroup(headPosition);
if (view==null){
view = layoutInflater.inflate(R.layout.list_header,null);
}
TextView headerTv = view.findViewById(R.id.headerTv);
headerTv.setText(heading+"");
headerTv.setBackgroundColor( Color.BLUE );
return view;
}
#Override
public View getChildView(int headPosition, int childPosition, boolean islastChild, View view, ViewGroup viewGroup) {
ChildDataModel child = (ChildDataModel) getChild(headPosition, childPosition);
if (view == null) {
view = layoutInflater.inflate(R.layout.child_item, null);
}
TextView childTv = (TextView) view.findViewById(R.id.childTv);
ImageView childImg = (ImageView) view.findViewById(R.id.childImg);
childTv.setText(child.getTitle());
if(child.getTitle().equalsIgnoreCase( "China" ))
{
childTv.setBackgroundColor( Color.RED );
}
childImg.setImageResource(child.getImage());
return view;
}
#Override
public boolean isChildSelectable(int headPosition, int childPosition) {
return true;
}
}
Here is ChildDataModel Class
public class ChildDataModel {
long id;
int image;
String title;
public ChildDataModel(int id, String country, int image) {
this.setId(id);
this.setTitle(country);
this.setImage(image);
}
public int getImage() {
return image;
}
public void setImage(int image) {
this.image = image;
}
public long getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
#Override
public String toString() {
Log.d("response ","ID: "+getId()+" Title: "+getTitle());
return super.toString();
}
}
Here is MainActivity Class
public class MainActivity extends AppCompatActivity {
ExpandableCustomAdapter expandableCustomAdapter;
ExpandableListView expandableListView;
List<String> headerData;
HashMap<String,ArrayList<ChildDataModel>> childData;
ChildDataModel childDataModel;
Context mContext;
ArrayList<ChildDataModel> asianCountries,africanCountries,nAmericanCountries,sAmericanCountries;
private int lastExpandedPosition = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
//initializing arraylists
headerData = new ArrayList<>();
childData = new HashMap<String,ArrayList<ChildDataModel>>();
asianCountries = new ArrayList<>();
africanCountries = new ArrayList<>();
nAmericanCountries = new ArrayList<>();
sAmericanCountries = new ArrayList<>();
// link listview from activity_main.xml
expandableListView = findViewById(R.id.expandAbleListView);
//populating data of world continents and their countries.
headerData.add("ASIA");
//adding countries to Asian continent
childDataModel = new ChildDataModel(1,"Afghanistan",R.drawable.afghanistan);
asianCountries.add(childDataModel);
childDataModel = new ChildDataModel(2,"China",R.drawable.china);
asianCountries.add(childDataModel);
childDataModel = new ChildDataModel(3,"India",R.drawable.india);
asianCountries.add(childDataModel);
childDataModel = new ChildDataModel(4,"Pakistan",R.drawable.pakistan);
asianCountries.add(childDataModel);
childData.put(headerData.get(0),asianCountries);
headerData.add("AFRICA");
//adding countries to African continent
childDataModel = new ChildDataModel(1,"South Africa",R.drawable.southafrica);
africanCountries.add(childDataModel);
childDataModel = new ChildDataModel(2,"Zimbabwe",R.drawable.zimbabwe);
childData.put(headerData.get(1),africanCountries);
headerData.add("NORTH AMERICA");
//adding countries to NORTH AMERICA continent
childDataModel = new ChildDataModel(1,"Canada",R.drawable.canada);
nAmericanCountries.add(childDataModel);
childData.put(headerData.get(2),nAmericanCountries);
headerData.add("SOUTH AMERICA");
//adding countries to SOUTH AMERICA continent
childDataModel = new ChildDataModel(1,"Argentina",R.drawable.argentena);
sAmericanCountries.add(childDataModel);
childData.put(headerData.get(3),sAmericanCountries);
//set adapter to list view
expandableCustomAdapter = new ExpandableCustomAdapter(mContext,headerData,childData);
expandableListView.setAdapter(expandableCustomAdapter);
//child click listener
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int headPosition, int childPosition, long id) {
Toast.makeText(mContext,
headerData.get(headPosition)
+ " has country "
+ childData.get(
headerData.get(headPosition)).get(
childPosition).getTitle(), Toast.LENGTH_SHORT)
.show();
return false;
}
});
//group expanded
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(int headPosition) {
if (lastExpandedPosition != -1
&& headPosition != lastExpandedPosition) {
expandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = headPosition;
Toast.makeText(mContext,
headerData.get(headPosition) + " continent expanded",
Toast.LENGTH_SHORT).show();
}
});
//group collapsed
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int headPosition) {
Toast.makeText(mContext,
headerData.get(headPosition) + " continent collapsed",
Toast.LENGTH_SHORT).show();
}
});
//Group Indicator
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
parent.smoothScrollToPosition(groupPosition);
if (parent.isGroupExpanded(groupPosition)) {
ImageView imageView = v.findViewById(R.id.expandable_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.arrow_right));
} else {
ImageView imageView = v.findViewById(R.id.expandable_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.arrow_down));
}
return false ;
}
});
}
}
I expect to handle it without event like setOnChildClickListener, setOnGroupExpandListener,setOnGroupCollapseListener, etc. Thanks for help
change getGroupView to:
#Override
public View getGroupView(int headPosition, boolean is_expanded, View view, ViewGroup headGroup) {
// Heading of each group
String heading = (String) getGroup(headPosition);
if (view==null){
view = layoutInflater.inflate(R.layout.list_header,null);
}
TextView headerTv = view.findViewById(R.id.headerTv);
headerTv.setText(heading+"");
boolean hasSelected = false;
ArrayList<ChildDataModel> childs =
childData.get(headerData.getItemAtIndex(headPosition));
for(int i=0;i<childs.size();i++){
if(childs.get(i).isSelected){
hasSelected = true;
}}
if(hasSelected)
headerTv.setBackgroundColor( Color.BLUE );
else
headerTv.setBackgroundColor( Color.RED);
return view;
}
you most highlight the header view when getGroupView executed if childs highl sign selected chileds and if selected eny then highlight header
Thank you #hunixa siuri It does work well. However Code must be edited a little as below
#Override
public View getGroupView(int headPosition, boolean is_expanded, View view, ViewGroup headGroup) {
// Heading of each group
String heading = (String) getGroup(headPosition);
if (view==null){
view = layoutInflater.inflate(R.layout.list_header,null);
}
TextView headerTv = view.findViewById(R.id.headerTv);
headerTv.setText(heading+"");
boolean hasSelected = false;
ArrayList<ChildDataModel> childs = childData.get(headerData.get(headPosition));
for(int i=0;i<childs.size();i++){
if(childs.get(i).getTitle().equalsIgnoreCase( "China" )){
hasSelected = true;
}}
if(hasSelected)
view.setBackgroundColor( Color.BLUE );
else
view.setBackgroundColor( Color.RED);
return view;
}

How to replace the baseadapter value and how to stop the pagination loading in android filter screen?

I have worked with the concept of filter that have to filter the job from job list based on skills and some list or there.
https://postimg.org/image/g3p1z6lbd/ - DashBoard Fragment.
About DashBoardFragment:
Contains job list view.
Dash Filter Button. - which redirect to the Filter screen.
public class DashBoardRefactor extends Fragment {
public static ProgressDialog progress;
public static List<DashListModel> dashRowList1 = new ArrayList<DashListModel>();
public static View footerView;
// #Bind(R.id.dashListView)
public static ListView dashListView;
int preCount = 2, scroll_Inc = 10, lastCount;
boolean flag = true;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dashboard_fragment, container, false);
ButterKnife.bind(this, v);
setHasOptionsMenu(true);
progress = new ProgressDialog(getActivity());
dashListView = (ListView) v.findViewById(R.id.dashListView);
footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dashboard_list_footer, null, false);
dashListView.addFooterView(footerView);
footerView.setVisibility(View.GONE);
dashRowList1.clear();
dashboardViewTask();
dashListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("onItemClick", "onItemClick <---- ");
Intent toPositionDetail = new Intent(getActivity(), PositionDetailScreenRefactor.class);
toPositionDetail.putExtra("id", dashRowList1.get(position).getDashId());
startActivity(toPositionDetail);
getActivity().overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
}
});
final int totalJobCount = SessionStores.gettotalJobList(getActivity());
Log.e("totalJobCount", "totalJobCount----" + totalJobCount);
dashListView.setOnScrollListener(new EndlessScrollListener(getActivity(), dashListView, footerView));
return v;
}
public void dashboardViewTask() {
progress.setMessage("Please Wait. It is Loading..job orders....");
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.show();
// footerView.setVisibility(View.VISIBLE);
Map<String, String> params = new HashMap<String, String>();
Log.e("candidate_id", "candidate_id---->" + SessionStores.getBullHornId(getActivity()));
params.put("candidate_id", SessionStores.getBullHornId(getActivity()));
params.put("page", "1");
new DashBoardTask(getActivity(), params, dashListView, footerView);
// progress.dismiss();
}
#Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
if (menu != null) {
menu.removeItem(R.id.menu_notify);
}
inflater.inflate(R.menu.menu_options, menu);
MenuItem item = menu.findItem(R.id.menu_filter);
item.setVisible(true);
getActivity().invalidateOptionsMenu();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.his__menu_accept:
Toast.makeText(getActivity(), "clicked dashboard menu accept", Toast.LENGTH_LONG).show();
return true;
case R.id.menu_filter:
// click evnt for filter
Toast.makeText(getActivity(), "clicked dashboard filter", Toast.LENGTH_LONG).show();
Intent filter_intent = new Intent(getActivity(), DashBoardFilterScreen.class);
startActivity(filter_intent);
getActivity().overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onPause() {
super.onPause();
// dashboardViewTask();
}}
DashBoardTask:
public class DashBoardTask {
public DashBoardTask(Context context, Map<String, String> params, ListView dashListView, View footerView) {
this.context = context;
Log.e("context ", "DashBoardTask: " + context);
this.dashListView = dashListView;
this.params = params;
this.footerView = footerView;
ResponseTask();
}
private void ResponseTask() {
new ServerResponse(ApiClass.getApiUrl(Constants.DASHBOARD_VIEW)).getJSONObjectfromURL(ServerResponse.RequestType.POST, params, authorizationKey, context, "", new VolleyResponseListener() {
#Override
public void onError(String message) {
if (DashBoardRefactor.progress.isShowing()) {
DashBoardRefactor.progress.dismiss();
}
}
#Override
public void onResponse(String response) {
//Getting Response and Assign into model Class
int currentPosition = dashListView.getFirstVisiblePosition();
dashListAdapter = new DashListAdapter(context, DashBoardRefactor.dashRowList1, dashListView);
dashListView.setAdapter(dashListAdapter);
((BaseAdapter) dashListAdapter).notifyDataSetChanged();
if (currentPosition != 0) {
// Setting new scroll position
dashListView.setSelectionFromTop(currentPosition + 1, 0);
}
if (footerView.isShown()) {
footerView.setVisibility(View.GONE);
}
//progress.dismiss();
if (DashBoardRefactor.progress.isShowing()) {
try {
DashBoardRefactor.progress.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
DashListAdapter:
________________
public class DashListAdapter extends BaseAdapter {
public static ListView dashListView;
Context c;
private LayoutInflater inflater;
private List<DashListModel> dashRowList;
public DashListAdapter(Context c, List<DashListModel> dashRowList, ListView dashListView) {
this.c = c;
this.dashListView = dashListView;
this.dashRowList = dashRowList;
}
#Override
public int getCount() {
return this.dashRowList.size();
}
#Override
public Object getItem(int position) {
return dashRowList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder dashHolder;
if (inflater == null)
inflater = (LayoutInflater) c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.dashboard_jobdetails_list, null);
Log.e("get pos", "get pooooossss---->" + dashRowList.get(position));
final DashListModel dashModel = dashRowList.get(position);
dashHolder = new ViewHolder(convertView);
//Assign the value into screen
dashHolder.dash_company_name.setText(dashModel.getDashCompanyName());
}
the above code for displaying dashboard fragment list.
https://postimg.org/image/nqvp1dud9/ - This link is FilterScreen
By using this image if i filter the job based on the designed UI detail. That should replace into the DashboadFragment list The result should display into the DashBoard Fragment. How can I add pagination on Filter screen the same which have in DashBoardFragment.

Get child view from ExpandableListView in FragmentActivity without childClick Event

I have several classes. First class extends from FragmentActivity, second class is adapter extends from BaseExpandableListAdapter. And Model Class.
First class:
public class CloseInformationTaskActivityList extends FragmentActivity implements ExpandableListView.OnChildClickListener {
private DAOFactory dao;
private ExpandListAdapter expAdapter;
private ExpandableListView expandList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
//task with all information passed in intent by reference
PRTarea task = (PRTarea) b.getSerializable("Task");
dao = new DAOFactory(this.getApplicationContext());
List<PRParametros> parametrosList = dao.getParametrosDAO().getParamsByTaskId(task.getId());
if (parametrosList.size() > 0) {
setContentView(R.layout.activity_task_parameters_list);
expandList = (ExpandableListView) findViewById(R.id.paramsExpandableListView);
ArrayList<Group> expListItems = setParamsGroups(parametrosList);
expAdapter = new ExpandListAdapter(CloseInformationTaskActivityList.this, expListItems, this);
expandList.setOnChildClickListener(this);
expandList.setAdapter(expAdapter);
} else {
setContentView(R.layout.activity_no_param_error);
}
// Set up the action bar.
final ActionBar actionBar = getActionBar();
// Specify that the Home/Up button should not be enabled, since there is no hierarchical
// parent.
assert actionBar != null;
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setTitle(R.string.task_information_title);
actionBar.setIcon(R.drawable.ic_arrow_back_white_24dp);
}
private ArrayList<Group> setParamsGroups(List<PRParametros> parametrosList) {
ArrayList<Group> paramGroupList = new ArrayList<>();
ArrayList<Child> ch_list = null;
Group grupo;
String holdIdGroup = "0";
//secure check
if (parametrosList != null && parametrosList.size() > 0) {
for (int i = 0; i < parametrosList.size(); i++) {
PRParametros parametro = parametrosList.get(i);
String idGrupo = parametro.getIdGrupo();
if (!idGrupo.equals(holdIdGroup)) {
holdIdGroup = idGrupo;
grupo = new Group();
ch_list = new ArrayList<>();
grupo.setName(dao.getGruposParametrosDAO().getGrupoById(idGrupo).getDescripcion());
grupo.setItems(ch_list);
paramGroupList.add(grupo);
}
Child child = new Child();
child.setName(parametro.getNombre());
if(parametro.getIdTipo().equals("12")){
if(parametro.getValor() != null){
paramValue = dao.getListaParametrosDAO().getValueParamById(Integer.valueOf(parametro.getValor()));
}
}
child.setValue(paramValue);
child.setType(Integer.valueOf(parametro.getIdTipo()));
child.setParamId(Integer.valueOf(parametro.getId()));
if (ch_list != null) {
ch_list.add(child);
}
}
}
return paramGroupList;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.btn_save_param:
saveParameters();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void saveParameters() {
Toast.makeText(getApplicationContext(),"Save parameters click", Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.save_parameters, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Child child = (Child) parent.getExpandableListAdapter().getChild(groupPosition,childPosition);
int itemType = child.getType();
switch (itemType){
case 12:
onCreateDialogSingleChoice(child, v);
break;
case 9:
openDateDialog(child, v);
break;
}
return false;
}
/**
* Open popup with single choice, refresh model data of child
* and assign selected value to textView
*
* #param child model with data
* #param view to asign selected value
*/
public void onCreateDialogSingleChoice(final Child child, final View view) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
List<PRListaParametros> listaParametros = dao.getListaParametrosDAO().getListParamsById(child.getParamId());
List<String> values = new ArrayList<>();
for(int i = 0; i < listaParametros.size(); i++){
values.add(listaParametros.get(i).getDescripcion());
}
final String[] items = values.toArray(new String[listaParametros.size()]);
final TextView label = (TextView) ((RelativeLayout) view).getChildAt(1);
builder.setTitle(R.string.task_information_param_popup_title);
builder.setSingleChoiceItems(items, 75, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
label.setText(items[which]);
child.setValue(items[which]);
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.task_information_param_popup_negative_button,new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
label.setText("");
}
});
builder.show();
}
}
Second class:
/**
* Adapter for expandable list with parameters
*/
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ArrayList<Group> groups;
private LayoutInflater mInflater;
public ExpandListAdapter(Context mContext, ArrayList<Group> groups) {
this.mContext = mContext;
this.groups = groups;
mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}
#Override
public boolean areAllItemsEnabled() {
return super.areAllItemsEnabled();
}
#Override
public View getChildView(int groupPosition, final int childPosition,
final boolean isLastChild, View convertView, ViewGroup parent) {
final Child child = (Child) getChild(groupPosition, childPosition);
final ViewHolder holder;
int itemType = child.getType();
holder = new ViewHolder();
if (itemType >= 1 && itemType <= 7) {
convertView = mInflater.inflate(R.layout.layout_edit_text_close_information, null);
holder.txtLabel = (TextView) convertView.findViewById(R.id.txt_task_detail_info_param);
holder.editText = (EditText) convertView.findViewById(R.id.txt_task_detail_info_param_input);
holder.editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
//refresh data in model
child.setValue(holder.editText.getText().toString());
}
});
}else if(itemType == 8){
convertView = mInflater.inflate(R.layout.layout_boolean_close_information, null);
holder.txtLabel = (TextView) convertView.findViewById(R.id.txt_task_detail_info_param_boolean_title);
holder.booleanSwitch = (Switch) convertView.findViewById(R.id.param_boolean_switch);
holder.booleanSwitch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String switchValue = "false";
if(holder.booleanSwitch.isChecked()){
switchValue = "true";
}
child.setValue(switchValue);
//mParamListener.onParameterViewClick(v, child);
}
});
}else {
convertView = mInflater.inflate(R.layout.layout_text_view_close_information, null);
holder.txtLabel = (TextView) convertView.findViewById(R.id.txt_task_detail_info_param_text_view);
holder.txtClickWithValue = (TextView) convertView.findViewById(R.id.txt_task_detail_info_param_click_text_view);
}
convertView.setTag(holder);
if (itemType >= 1 && itemType <= 7) {
holder.txtLabel.setText(child.getName());
holder.editText.setText(child.getValue());
switch (itemType){
case 1:
holder.editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
holder.editText.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
break;
case 2:
holder.editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
holder.editText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
break;
case 6:
holder.editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
holder.editText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
if(!holder.editText.getText().toString().isEmpty()){
if(!isValidIp(holder.editText.getText().toString())){
holder.editText.setError("IPv 4 no valido");
}
}
break;
case 7:
holder.editText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
if(!holder.editText.getText().toString().equals("")){
if(!isValidIp(holder.editText.getText().toString())){
holder.editText.setError("IPv 6 no valido");
}
}
holder.editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
if(!isValidIp(holder.editText.getText().toString())){
holder.editText.setError("IPv 6 no valido");
}
}
});
break;
}
}else if(itemType == 8) {
boolean value = Boolean.valueOf(child.getValue());
holder.txtLabel.setText(child.getName());
if(value){
holder.booleanSwitch.setTextOn(mContext.getResources().getString(R.string.task_information_param_boolean_switch_on));
holder.booleanSwitch.setChecked(true);
}else{
holder.booleanSwitch.setTextOff(mContext.getResources().getString(R.string.task_information_param_boolean_switch_off));
holder.booleanSwitch.setChecked(false);
}
}else {
holder.txtLabel.setText(child.getName());
holder.txtClickWithValue.setText(child.getValue());
}
return convertView;
}
#Override
public void registerDataSetObserver(DataSetObserver observer) {
super.registerDataSetObserver(observer);
//call notifyDataSetChanged() for refresh data model in view
}
public static class ViewHolder {
public TextView txtLabel;
public EditText editText;
public TextView txtClickWithValue;
public Switch booleanSwitch;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public int getChildrenCount(int groupPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.size();
}
#Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
#Override
public int getGroupCount() {
return groups.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Group group = (Group) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.activity_task_parameters_group, null);
}
TextView groupTitle = (TextView) convertView.findViewById(R.id.param_group_name);
groupTitle.setText(group.getName());
TextView groupCount = (TextView) convertView.findViewById(R.id.param_group_count);
int countParam = getChildrenCount(groupPosition);
if(countParam > 1){
groupCount.setText(getChildrenCount(groupPosition) + " " +
mContext.getResources().getString(R.string.task_information_param_group_count_title));
}else{
groupCount.setText(getChildrenCount(groupPosition) + " " +
mContext.getResources().getString(R.string.task_information_param_group_count_title_single));
}
if (isExpanded) {
convertView.setBackgroundResource(R.color.group_param_expanded);
} else {
convertView.setBackgroundResource(0);
}
return convertView;
}
#Override
public int getChildType(int groupPosition, int childPosition) {
return super.getChildType(groupPosition, childPosition);
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
/**
* #param ip the ip
* #return check if the ip is valid ipv4 or ipv6
*/
private static boolean isValidIp(final String ip) {
return InetAddressUtils.isIPv4Address(ip) || InetAddressUtils.isIPv6Address(ip);
}
}
Model Class
/**
* Model of each parameters
*/
public class Child {
private String name;
private String value;
private int type;
private int paramId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getParamId() {
return paramId;
}
public void setParamId(int paramId) {
this.paramId = paramId;
}
}
XML View of each child by type, possible type is EditText, TextView, Switch, popup list with single choice.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:id="#+id/txt_task_detail_info_param"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:minWidth="150dp"
android:focusable="false"
android:clickable="false"
android:padding="20dp"
android:textSize="14sp"
android:layout_toLeftOf="#+id/txt_task_detail_info_param_input"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/txt_task_detail_info_param_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"
android:maxWidth="200dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="14sp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
Layout have action bar with save button:
|------------------Save button--|
| <ExpandableList> | |
| group1 | |
| child1: textView EditText | |
| child2: textView Switch | |
| group2 | |
| child1: textView TextView | |
|-------------------------------|
I am trying to get values of child view for save it in database, before i need check each field by type for valid data.
Currently i am checking the values in adapter and works well. Possibly not the right way...
But how to get value of each view by type only clicking save button in FragmentActivity in action bar??
I am trying onChildClick but click event by editText not working. Thanks!
SOLVED
Now I have resolved, but I think is not the right way for do it.
In model class Child i created new field with View.
private View view;
and assigned complete View by type (editText,TextView, etc) in adapter getChildView for example:
child.setView(holder.editText);
and finally use in FragmentActivity
private void checkParameters() {
boolean validated = true;
int groupCount = expandList.getExpandableListAdapter().getGroupCount();
for (int i = 0; i < groupCount; i++) {
int childCount = expandList.getExpandableListAdapter().getChildrenCount(i);
for (int j = 0; j < childCount; j++) {
Child child = (Child) expandList.getExpandableListAdapter().getChild(i, j);
//secure check
if (child.getView() != null) {
int itemType = child.getType();
//only editText
if (itemType >= 1 && itemType <= 7) {
EditText ed = (EditText) child.getView();
//do something
}
}
}
}
}
Anyone know how to do this more efficiently???

ExpandableListView selected item lost on group collapse

I have an ExpandableListView on a fragment and when I choose an item I am changing the background and text colour of this item (TextView). This works fine. However when I collapse the group which contains the currently selected item, the selection is lost. How can I stop this from happening/set the selected item back to what it should be?
I have tried messing around with the onGroupExpand/CollapseListener's but not had any success. For example I have tried this:
_list.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
_list.setItemChecked(_activePosition, true);
}
});
Note: _list and _activePosition are declared at class level.
Here is my code for setting the checked item, from the examples I've seen I think this is standard practice, but please advise if not as I'm new to android.
HelpItemsFragment.java
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final List<HelpCategory> itemList = new ArrayList<HelpCategory>();
HelpCategory helpCategory;
//replace this with database stuff later
helpCategory = new HelpCategory();
helpCategory.setTitle("Group 1");
helpCategory.addHelpItem(new HelpItem((long) 1, "1.1", "Details for 1.1"));
helpCategory.addHelpItem(new HelpItem((long) 1, "1.2", "Details for 1.2"));
helpCategory.addHelpItem(new HelpItem((long) 1, "1.3", "Details for 1.3"));
itemList.add(helpCategory);
helpCategory = new HelpCategory();
helpCategory.setTitle("Group 2");
helpCategory.addHelpItem(new HelpItem((long) 2, "2.1", "Details for 2.1"));
helpCategory.addHelpItem(new HelpItem((long) 2, "2.2", "Details for 2.2"));
helpCategory.addHelpItem(new HelpItem((long) 2, "2.3", "Details for 2.3"));
itemList.add(helpCategory);
HelpExpandableListAdapter listAdapter = new HelpExpandableListAdapter(this.getActivity(), itemList);
_list.setAdapter(listAdapter);
_list.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
HelpItem helpItem = itemList.get(groupPosition).getHelpItemList().get(childPosition);
_activePosition = index;
_callback.onItemSelected(null, helpItem.getTitle(), helpItem.getDetail(), _activePosition);
parent.setItemChecked(index, true);
return true;
}
});
Adapter class HelpExpandableListAdapter should be like
public class HelpExpandableListAdapter extends BaseExpandableListAdapter {
private LayoutInflater inflater;
private ArrayList<CategoryGroup> mParent;
public ExpandableListItems(Context context, ArrayList<CategoryGroup> parent) {
mParent = parent;
inflater = LayoutInflater.from(context);
}
#Override
//counts the number of parent items so the list knows how many times calls getGroupView() method
public int getGroupCount() {
return mParent.size();
}
#Override
//counts the number of children items so the list knows how many times calls getChildView() method
public int getChildrenCount(int i) {
return mParent.get(i).getArrayChildren().size();
}
#Override
//gets the title of each parent/group
public Object getGroup(int i) {
return mParent.get(i).getTitle();
}
#Override
//gets the name of each item
public Object getChild(int i, int i1) {
return mParent.get(i).getArrayChildren().get(i1);
}
#Override
public long getGroupId(int i) {
return i;
}
#Override
public long getChildId(int i, int i1) {
return i1;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
//in this method you must set the text to see the parent/group on the list
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
System.out.println("i: " + i + "; b: " + b );
view = inflater.inflate(R.layout.grouprow, viewGroup, false);
}
TextView textView = (TextView) view.findViewById(R.id.rowname);
//"i" is the position of the parent/group in the list
textView.setText(getGroup(i).toString());
//return the entire view
return view;
}
#Override
//in this method you must set the text to see the children on the list
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.childrow, viewGroup, false);
}
TextView textView = (TextView) view.findViewById(R.id.grpchild);
//"i" is the position of the parent/group in the list and
//"i1" is the position of the child
textView.setText(mParent.get(i).getArrayChildren().get(i1));
//return the entire view
return view;
}
#Override
public boolean isChildSelectable(int i, int i1) {
return true;
}
#Override
public void registerDataSetObserver(DataSetObserver observer) {
/* used to make the notifyDataSetChanged() method work */
super.registerDataSetObserver(observer);
}
}
Group class
public class CategoryGroup {
private String mTitle;
private ArrayList<String> mArrayChildren;
public String getTitle() {
return mTitle;
}
public void setTitle(String mTitle) {
this.mTitle = mTitle;
}
public ArrayList<String> getArrayChildren() {
return mArrayChildren;
}
public void setArrayChildren(ArrayList<String> mArrayChildren) {
this.mArrayChildren = new ArrayList(mArrayChildren);
}
}
In the onCreateView()
ArrayList<CategoryGroup> arrayParentsGroups = new ArrayList<CategoryGroup>();
arrayParentsGroups = createGroupList();
listAdapter = new HelpExpandableListAdapter(this, arrayParentsGroups);
_list.setAdapter(listAdapter);
private List createGroupList() {
ArrayList arrayParents = new ArrayList();
for( int i = 0 ; i < 10 ; ++i ) { // 10 groups........
CategoryGroup parent = new CategoryGroup();
parent.setTitle("Group row" + i);
ArrayList<String> arrayChildren = new ArrayList<String>();
for (int j = 0; j < 3; j++) {
arrayChildren.add("Child row" + j);
}
parent.setArrayChildren(arrayChildren);
arrayParents.add(parent);
}
return arrayParents;
}

StaggeredGridView refresh correctly only top

I use https://github.com/bulletnoid/StaggeredGridView this library for make a pinterest style layout and use pulltorefresh on this layout. Also ı have a slide menu for choose different category and according to category which is user choose, refresh and refill the staggred again.
Pulltorefresh is work fine.
if user top of the layout and choose a category on slide menu it's work correctly. But if user bottom of the layout and choose a category on slide menu it's work not correctly .
the scenario, top of layout and select category on slidemenu and refill staggered layout. it's work correctly
the scenario, bottom of layout and select category on slidemenu and refill staggered layout. it's not work correctly
-->listviewAdapter
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
// TODO Auto-generated method stub
switch (parent.getId()) {
case R.id.listView_sliding_menu:
smenu.toggle();
slidingMenuControl = true;
String categoryId = ((TextView) view.findViewById(R.id.categoryID))
.getText().toString();
parameters[0] = categoryId;
Toast.makeText(getApplicationContext(), categoryId,
Toast.LENGTH_LONG).show();
new PARSEJSONCATEGORYCONTENT().execute(parameters);
break;
default:
break;
}
}
-->parser
private class PARSEJSONCATEGORYCONTENT extends
AsyncTask<String[], Void, ArrayList<Utils>> {
#Override
protected void onPreExecute() {
super.onPreExecute();
processDialoge();
}
protected ArrayList<Utils> doInBackground(String[]... params) {
String catId = params[0][0];
String startCount = params[0][5];
String count = params[0][6];
String urlCatContent = "http://212.58.8.109/webservice/api/content/cat/";
jArray = jsonParser.getJSONFromUrltoCategoryContent(urlCatContent,
Token, tokenValue, catId, startCount, count);
if (utilsArray == null) {
utilsArray = new ArrayList<Utils>();
} else if (slidingMenuControl == true) {
utilsArray.clear();
} else if (contentItemSelection != null) {
utilsArray.clear();
}
try {
// looping through All Contacts
for (int i = 0; i < jArray.length(); i++) {
JSONObject k = jArray.getJSONObject(i);
utils = new Utils();
// Storing each json item in variable
utils.imageUrl = k.getString("ipad_URL");
utils.imageWidth = k.getInt("ipad_width");
utils.imageHeight = k.getInt("ipad_height");
utils.categoryHeader = k.getString("contentHeader");
utils.contentDesc = k.getString("contentDesc");
utils.categoryContentId = k.getInt("id");
utils.contentTxt = k.getString("contentTxt");
Log.d("ipad_URL", utils.imageUrl);
utilsArray.add(utils);
}
String arrayLenght = Integer.toString(utilsArray.size());
Log.d("arrayLenght", arrayLenght);
} catch (JSONException e) {
e.printStackTrace();
}
return utilsArray;
}
protected void onPostExecute(ArrayList<Utils> utilsArray) {
staggeredAdapter.getMoreItemm(utilsArray);
// staggeredAdapter.setRefreshListener(false);
super.onPostExecute(utilsArray);
slidingMenuControl = false;
dialog.cancel();
}
}
-->BaseAdapter.java
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#SuppressLint("NewApi")
public class StaggeredAdapter extends BaseAdapter implements OnClickListener {
Typeface tf;
boolean refreshListener = false;
Utils utils;
private Context mContext;
private Application mAppContext;
private ArrayList<Utils> mUtilsArraylist = new ArrayList<Utils>();
public StaggeredAdapter(Context context, Application application) {
mContext = context;
mAppContext = application;
tf = Typeface.createFromAsset(mContext.getAssets(),
"font/Klavika-Medium.otf");
notifyDataSetChanged();
}
public void getMoreItemm(ArrayList<Utils> arrayList) {
mUtilsArraylist.clear();
mUtilsArraylist.addAll(arrayList);
this.notifyDataSetChanged();
}
public int getCount() {
return mUtilsArraylist == null ? 0 : mUtilsArraylist.size();
}
#Override
public Object getItem(int position) {
return mUtilsArraylist.get(position);
}
#Override
public long getItemId(int position) {
return mUtilsArraylist.indexOf(getItem(position));
}
#SuppressLint("NewApi")
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
utils = mUtilsArraylist.get(position);
if (convertView == null) {
Holder holder = new Holder();
view = View.inflate(mContext, R.layout.staggered_item, null);
holder.imgUrl_content = (STGVImageView) view
.findViewById(R.id.imgUrl_content);
holder.tv_info = (TextView) view.findViewById(R.id.contentHeader);
holder.tv_info.setTypeface(tf);
holder.tv_info2 = (TextView) view.findViewById(R.id.contentDesc);
holder.tv_info2.setTypeface(tf);
view.setTag(holder);
} else {
return convertView;
}
final Holder holder = (Holder) view.getTag();
holder.imgUrl_content.mHeight = utils.imageHeight;
holder.imgUrl_content.mWidth = utils.imageWidth;
holder.imgUrl_content.setOnClickListener(this);
ImageLoader imgLoader = new ImageLoader(mAppContext);
imgLoader.DisplayImage(utils.imageUrl, holder.imgUrl_content);
holder.tv_info.setText(utils.categoryHeader);
holder.tv_info.setOnClickListener(this);
holder.tv_info2.setText(utils.contentDesc);
holder.tv_info2.setOnClickListener(this);
return view;
}
class Holder {
public STGVImageView imgUrl_content;
public TextView tv_info;
public TextView tv_info2;
}
public boolean isRefreshListener() {
return refreshListener;
}
public void setRefreshListener(boolean refreshListener) {
this.refreshListener = refreshListener;
}
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.imgUrl_content:
sendDataItemContentActivity();
break;
case R.id.contentHeader:
sendDataItemContentActivity();
break;
case R.id.contentDesc:
sendDataItemContentActivity();
break;
default:
break;
}
}
public void sendDataItemContentActivity() {
Intent intent = new Intent(mContext, ItemContent.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("contentTxt", utils.contentTxt);
intent.putExtra("contentHeader", utils.categoryHeader);
intent.putExtra("contentİmageUrl", utils.imageUrl);
intent.putExtra("contentCategoryName", utils.categoryName);
Bundle animBundle = ActivityOptions.makeCustomAnimation(mContext,
R.anim.anim, R.anim.anim2).toBundle();
mContext.startActivity(intent, animBundle);
}
}
I guess i had a same problem with using the same pinterest style library with you. i solve my problem by put this
#Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
mAdapter = new SearchSTGVAdapter(getActivity(), adsList, (Fragment)this);
ptrstgv.setAdapter(mAdapter);
}
which previously I put it in the onCreate method
For your information, I am implement this pinterest style in a view pager not a sliding menu

Categories

Resources