I use PulltoRefresh listview and I use 3 layouts.
1. Gaming Layout(Should be inflated when linkedlist item starts with "gm")
2. Adlayout(Should be inflated when linkedlist item starts with "ad")
3.Normal Listview layout(in all other cases)
Here is the code
mListItems = new LinkedList<String>();
mListItems.add(0,"hi1");
mListItems.add(1,"hi2");
mListItems.add(2,"gm");
mListItems.add(3,"hi3");
mListItems.add(4,"ad");
mListItems.add(5,"hi4");
((PullToRefreshListView) getListView())
.setOnRefreshListener(new OnRefreshListener() {
#Override
public void onRefresh() {
// Do work to refresh the list here.
new GetDataTask().execute();
}
});
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
#Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
;
}
return mStrings;
}
#Override
protected void onPostExecute(String[] result) {
// mListItems.addFirst("Added after refresh...");
// parseJson("IndigoFM_06212013.json");
mListItems.addFirst("how are you");
mListItems.addFirst("ad");
mListItems.addFirst("gm");
mListItems.addFirst("the end");
// Call onRefreshComplete when the list has been refreshed.
((PullToRefreshListView) getListView()).onRefreshComplete();
super.onPostExecute(result);
}
}
Here is the adapter code
private class basicListAdapter extends BaseAdapter {
#Override
public int getCount() {
// TODO Auto-generated method stub
return mListItems.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mListItems.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if (v == null) {
LayoutInflater inflater = LayoutInflater
.from(getApplicationContext());
if ((mListItems.get(position).startsWith("gm"))) {
v = inflater.inflate(R.layout.gaminglayout, null);
} else if ((mListItems.get(position).startsWith("ad"))) {
v = inflater.inflate(R.layout.adlayout, null);
} else if(!(mListItems.get(position).startsWith("gm")) && !(mListItems.get(position).startsWith("ad"))) {
v = inflater.inflate(R.layout.listinflate, null);
}
viewHolder holder = new viewHolder();
adViewHolder adHolder = new adViewHolder();
gamingViewHolder gamingHolder = new gamingViewHolder();
if ((mListItems.get(position).startsWith("ad"))) {
adHolder.adDetails = (TextView) v.findViewById(R.id.adText);
v.setTag(adHolder);
} else if ((mListItems.get(position).startsWith("gm"))) {
gamingHolder.gamingButton = (Button) v
.findViewById(R.id.gamingButton);
gamingHolder.gamingButton .setOnClickListener(mOngamingButtonClickListener);
v.setTag(gamingHolder);
}else if(!(mListItems.get(position).startsWith("gm")) && !(mListItems.get(position).startsWith("ad"))){
holder.rjName = (TextView) v.findViewById(R.id.rjName);
holder.textViewName = (TextView) v
.findViewById(R.id.textViewName);
holder.likeLayout = (LinearLayout) v
.findViewById(R.id.likeLayout);
holder.commentLayout = (LinearLayout) v
.findViewById(R.id.commentLayout);
holder.likeLayout
.setOnClickListener(mOnLikeLayoutClickListener);
holder.commentLayout
.setOnClickListener(mOnCommentLayoutClickListener);
v.setTag(holder);
}
}
if (mListItems.get(position) != null) {
// if(!(mListItems.get(position).startsWith("1"))){
if (!(v.getTag() instanceof adViewHolder)) {
if(!(v.getTag() instanceof gamingViewHolder)){
viewHolder holder = (viewHolder) v.getTag();
holder.textViewName.setText(mListItems.get(position));
}
}
}
return v;
}
}
Now the issue is that after I pull to refresh, The entries which start with "gm" are being shown in normal listview layout but not the gaming layout.
In a way to say incorrect layout is being inflated
Related
I have a custom listview, include an imageview and a textview.
I want, when I click imageview in this, start animation(rotate).
My problem is: When scrolling, animation stopped.
public class AdapterFoodGroups extends BaseAdapter {
private static LayoutInflater mInflater = null;
Context context;
int[] foodImagesId;
String[] foodNameList;
String[] foodDescriptions;
int[] foodTimes;
boolean[] loadAnimation;
public AdapterFoodGroups(Context context, String[] foodNameList, String[] foodDescriptions, int[] foodTimes, int[] foodImagesId) {
// TODO Auto-generated constructor stub
this.foodNameList = foodNameList;
this.foodDescriptions = foodDescriptions;
this.foodTimes = foodTimes;
this.foodImagesId = foodImagesId;
this.context = context;
loadAnimation = new boolean[foodNameList.length];
for (boolean b: loadAnimation) {
b = false;
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder viewHolder;
final RotateAnimation anim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5 f, Animation.RELATIVE_TO_SELF, 0.5 f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(800);
if (convertView == null) {
mInflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.adapter_foodgroup, null);
viewHolder = new ViewHolder();
viewHolder.txtFoodName = (TextView) convertView.findViewById(R.id.txtFoodNameGrid);
viewHolder.txtFoodDescription = (TextView) convertView.findViewById(R.id.txtFoodDescriptionGrid);
viewHolder.txtFoodTime = (TextView) convertView.findViewById(R.id.txtFoodTimeGrid);
viewHolder.ivFoodImage = (CircularImageView) convertView.findViewById(R.id.ivFoodImageGrid);
viewHolder.ivLoad = (ImageView) convertView.findViewById(R.id.ivLoad);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (this.foodImagesId[position] != 0) {
viewHolder.ivFoodImage.setImageResource(this.foodImagesId[position]);
viewHolder.ivFoodImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, String.valueOf(position) + " = " + foodNameList[position], Toast.LENGTH_LONG).show();
}
});
}
if (this.foodNameList[position] != null) {
viewHolder.txtFoodName.setText(this.foodNameList[position]);
}
if (this.foodDescriptions[position] != null) {
viewHolder.txtFoodDescription.setText(this.foodDescriptions[position]);
}
if (this.foodTimes[position] != 0) {
viewHolder.txtFoodTime.setText(String.valueOf(this.foodTimes[position]) + " دقیقه");
}
viewHolder.ivLoad.setImageResource(R.drawable.load);
viewHolder.ivLoad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
viewHolder.ivLoad.setAnimation(anim);
viewHolder.ivLoad.startAnimation(anim);
}
});
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return foodNameList.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public static class ViewHolder {
public CircularImageView ivFoodImage;
public ImageView ivLoad;
public TextView txtFoodName;
public TextView txtFoodDescription;
public TextView txtFoodTime;
}
}
Try this:
In your adapter constructor change these lines:
....
loadAnimation = new boolean[foodNameList.length];
for (int i=0; i < loadAnimation.length; i++) {
loadAnimation[i] = false;
}
....
In getView() method add this:
...
viewHolder.ivLoad.setImageResource(R.drawable.load);
if(loadAnimation[position]){
viewHolder.ivLoad.setAnimation(anim);
viewHolder.ivLoad.startAnimation(anim);
} else {
viewHolder.ivLoad.setAnimation(null);
}
viewHolder.ivLoad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
viewHolder.ivLoad.setAnimation(anim);
viewHolder.ivLoad.startAnimation(anim);
loadAnimation[position] = true;
}
});
...
Hope it helps!
Hi i am doing an application in which i want to show the content depending on the custom and the public ,data is coming from the sever.i am receiving the is_public as a parameter value as 0 and 1 if it is 1 it for public, we need to display to all user if t is 0,we need to display only the custom member like user id 8,10. for rest of the user the received content like user id 11 need to be invisible.
i able to make invisible the content, when i invisible it it is taking blank space in the list view how to remove the blank space i am posting my adapter class below
please help me
public class PlacementsBoardAdapter extends BaseAdapter{
private ArrayList<PlacementsBoardModel> listData;
private LayoutInflater layoutInflater;
ArrayList<PlacementsBoardModel> listData1;
public ImageLoader imageLoader;
DisplayImageOptions profile_options;
ImageView imageview;
private Context prova;
Bitmap bit_map_image;
int isPublic;
String custom;
public PlacementsBoardAdapter(Context context,ArrayList<PlacementsBoardModel> listData){
this.listData = listData;
listData1=listData;
prova = context;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return listData.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return listData.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
imageLoader =imageLoader.getInstance();
profile_options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.pdfimage)
.showImageForEmptyUri(R.drawable.pdfimage)
.showImageOnFail(R.drawable.pdfimage)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
final ViewHolder holder;
if (layoutInflater == null)
layoutInflater = (LayoutInflater) prova.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = layoutInflater.inflate(R.layout.placementsboardcutomview, null);
holder = new ViewHolder();
/*holder.title_of_placesment = (TextView) convertView.findViewById(R.id.title_of_placesment);
holder.pdf_image_custom=(ImageView)convertView.findViewById(R.id.pdf_image_custom);
holder.created_date = (TextView) convertView.findViewById(R.id.created_date);*/
holder.title_of_placesment = (TextView) convertView.findViewById(R.id.noticetopic);
holder.pdf_image_custom=(ImageView)convertView.findViewById(R.id.notice_title_name_image);
holder.readmore=(TextView)convertView.findViewById(R.id.readmore);
holder.placement_etext = (TextView) convertView.findViewById(R.id.noticetext);
holder.readmorelayout=(RelativeLayout)convertView.findViewById(R.id.bottom_layout);
holder.created_date = (TextView) convertView.findViewById(R.id.createddate);
holder.placementCustomLinear=(LinearLayout)convertView.findViewById(R.id.placementCustomLinear);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
final PlacementsBoardModel placementboardItem = (PlacementsBoardModel) listData.get(position);
holder.title_of_placesment.setText(placementboardItem.getTitle());
holder.created_date.setText(placementboardItem.getCreated_date());
holder.placement_etext.setText(placementboardItem.getDescription());
String description=placementboardItem.getDescription();
isPublic=placementboardItem.getIsPublic();
custom=placementboardItem.getCustom();
if (description!=null&&!placementboardItem.getDownload_file_path().contains("null")) {
holder.placement_etext.setVisibility(View.VISIBLE);
holder.pdf_image_custom.setVisibility(View.VISIBLE);
if(isPublic==0&&Util.USER_ID.contains(custom)){
holder.placementCustomLinear.setVisibility(View.VISIBLE);
}
if (description.length()>350) {
holder.placement_etext.setText(placementboardItem.getDescription().trim().subSequence(0, 300)+"....");
holder.readmorelayout.setVisibility(View.VISIBLE);
}
}
else if(description!=null&&placementboardItem.getDownload_file_path().contains("null")){
if (description.length()>350) {
holder.placement_etext.setText(placementboardItem.getDescription().trim().subSequence(0, 300)+"....");
holder.readmorelayout.setVisibility(View.VISIBLE);
}
else{
holder.readmorelayout.setVisibility(View.GONE);
holder.placement_etext.setVisibility(View.VISIBLE);
holder.pdf_image_custom.setVisibility(View.GONE);
}
}
if(placementboardItem.getDescription().contains("null")&&!placementboardItem.getDownload_file_path().contains("null")) {
holder.placement_etext.setVisibility(View.GONE);
holder.pdf_image_custom.setVisibility(View.VISIBLE);
holder.readmorelayout.setVisibility(View.GONE);
}
//holder.pdf_image_custom.setBackground(background)
if (placementboardItem.getDownload_file_type().contains("jpg")||placementboardItem.getDownload_file_type().contains("jpeg")||placementboardItem.getDownload_file_type().contains("png")) {
Log.i("only jpg or png", "tittle the file for display");
if (placementboardItem.getTitle().length()>=20) {
holder.title_of_placesment.setText(placementboardItem.getTitle().trim().subSequence(0, 20)+"....");
//holder.imageview.setImageBitmap(noticeboardItem.getBit_image());
}else{
//noticeboardItem.getBit_image()
holder.title_of_placesment.setText(placementboardItem.getTitle());
holder.pdf_image_custom.setImageBitmap(bit_map_image);
}
} else {
if (placementboardItem.getTitle().length()>=20) {
holder.title_of_placesment.setText(placementboardItem.getTitle().trim().subSequence(0, 20)+"....");
//holder.imageview.setImageResource(R.drawable.pdfimage);
}else{
holder.title_of_placesment.setText(placementboardItem.getTitle());
//holder.imageview.setImageResource(R.drawable.pdfimage);
Log.i("only pdf", "only pdf");;
}
}
if(isPublic==1&&!Util.USER_ID.contains(custom)){
holder.placementCustomLinear.setVisibility(View.VISIBLE);
}
holder.pdf_image_custom.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PlacementsBoardModel notice_data = (PlacementsBoardModel) listData.get(position);
/*String title=notice_data.getTitle();
String description=notice_data.getDescription();
Intent intent = new Intent(prova,DscriptionDisplay.class);
intent.putExtra("title",title);
intent.putExtra("description",description);
prova.startActivity(intent);*/
if (notice_data.getDownload_file_type().contains("jpg")||notice_data.getDownload_file_type().contains("gif")||notice_data.getDownload_file_type().contains("jpeg")||notice_data.getDownload_file_type().contains("png")) {
Log.i("only jpg or png", "tittle the file for display");
Intent intent1 = new Intent(prova,NoticeBoardImageDisplayActivity.class);
intent1.putExtra("noticeimagelink",notice_data.getDownload_file_path());
intent1.putExtra("noticetitle",notice_data.getTitle());
prova.startActivity(intent1);
} else {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notice_data.getDownload_file_path()));
prova.startActivity(browserIntent);
Log.i("only pdf", "only pdf");
}
notifyDataSetChanged();
}
});
holder.readmore.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//placementboardItem = (PlacementsBoardModel) listData.get(position);
String title=placementboardItem.getTitle();
String description=placementboardItem.getDescription();
Intent intent = new Intent(prova,DscriptionDisplay.class);
intent.putExtra("title",title);
intent.putExtra("description",description);
prova.startActivity(intent);
notifyDataSetChanged();
}
});
imageLoader.displayImage(placementboardItem.getDownload_file_path(), holder.pdf_image_custom, profile_options, new SimpleImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
}
#Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
//bit_map_image=loadedImage;
}
}, new ImageLoadingProgressListener() {
#Override
public void onProgressUpdate(String imageUri, View view, int current,
int total) {
}
}
);
notifyDataSetChanged();
return convertView;
}
static class ViewHolder{
RelativeLayout readmorelayout;
TextView placement_etext;
TextView readmore;
TextView title_of_placesment;
TextView created_date;
ImageView pdf_image_custom;
LinearLayout placementCustomLinear;
}
}
holder.placementCustomLinear is the custom leaner-layout need to be make it invisible
After some research i have solved my problem by adding a parent layout in the the xml and adding the some logic in the adapter class like
if (Util.ROLE.equalsIgnoreCase("admin")) {
holder.placementCustomLinear.setVisibility(View.VISIBLE);
}else
if(isPublic==0){
Log.i("inside if ", ""+isPublic);
Log.i("custom disply", custom);
int[] arry= stringToInteger(custom);
Log.i("numbers to ccheck ", ""+(arry));
for (int i = 0; i < arry.length; i++) {
if(custom.contains(Util.USER_ID)){
Log.i("true checked ", "inside");
holder.placementCustomLinear.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}else{
holder.placementCustomLinear.setVisibility(View.GONE);
notifyDataSetChanged();
}
}
if(isPublic==0&&Util.USER_ID.contains(custom)){
holder.placementCustomLinear.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}
}
else{
Log.i("else block ",""+isPublic);
if(isPublic==1)
holder.placementCustomLinear.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}
my problem is solved thanks for the people who have give some suggestion
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
I am trying to getting the total Count of the getView custom listview. But want to display in the different layout. Here is my onCreatedView. I am not sure how to inflate the layout. Thanks for all your help.
private static ListView addDropListView = null;
private TransactionAddDropAdapter addDropAdapter = null;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fragmentPendingTrades = inflater.inflate(R.layout.fragment_transactions_pending, container, false);
pendingTradesView = inflater;
return fragmentPendingTrades;
}
public void onViewCreated(final View view, final Bundle savedInstanceState) {
this.addDropListView = (ListView) view.findViewById(R.id.transactions_pending_transactionsListView);
this.addDropAdapter = new TransactionAddDropAdapter(pendingTradesView);
this.addDropListView.setAdapter(this.addDropAdapter);
this.emptyTransationsContainer = view.findViewById(R.id.transactions_pending_transactions_emptyContainer);
TextView getTotalCount = (TextView) view.findViewById(R.id.transactions_pending_TransactionsAddDropCount);
getTotalCount.setText(""+addDropListView.getCount());
}
Here is my Holderview that get the getView
public class TransactionAddDropAdapter extends BaseAdapter {
private LayoutInflater inflater = null;
private List<TransactionAddDrop> addDropList = new ArrayList<TransactionAddDrop>();
public TransactionAddDropAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
public void setAddDropList(List<TransactionAddDrop> addDropList) {
clearAddDropList();
for (TransactionAddDrop ad : addDropList) {
if (ad.isStateApprove()) {
this.addDropApprovalsList.add(ad);
} else {
this.addDropList.add(ad);
}
}
}
public void clearAddDropList() {
this.addDropList.clear();
this.addDropApprovalsList.clear();
}
#Override
public int getCount() {
int size = this.addDropList.size();
if (this.addDropApprovalsList.size() > 0) {
size += 1;
}
return size;
}
#Override
public Object getItem(int position) {
try {
if (this.addDropList == null) {
return null;
} else if (position < addDropList.size()) {
return this.addDropList.get(position);
} else {
return this.addDropApprovalsList;
}
} catch (Exception e) {
return null;
}
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final TransactionAddDrop addDropData = this.addDropList.get(position);
TransactionAddDropViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.fragment_pending_transaction_list_item, null);
holder = new TransactionAddDropViewHolder();
holder.withdrawButton = convertView.findViewById(R.id.pendingTransactionItem_withdrawButton);
holder.addContainer = (LinearLayout) convertView.findViewById(R.id.pendingTransactionItem_addContainer);
holder.dropContainer = (LinearLayout) convertView.findViewById(R.id.pendingTransactionItem_dropContainer);
holder.rootView = convertView.findViewById(R.id.swipeRight);
holder.swipeButtons();
convertView.setTag(holder);
} else {
holder = (TransactionAddDropViewHolder) convertView.getTag();
holder.swipeButtons();
}
}
Ok, I "think" I know what's going on here. You setup your ListView and add its TransactionAddDropAdapter, and then set the total amount of items.
this.addDropListView = (ListView) view.findViewById(R.id.transactions_pending_transactionsListView);
this.addDropAdapter = new TransactionAddDropAdapter(pendingTradesView);
this.addDropListView.setAdapter(this.addDropAdapter);
TextView getTotalCount = (TextView) view.findViewById(R.id.transactions_pending_TransactionsAddDropCount);
getTotalCount.setText(""+addDropListView.getCount());
However, at this point, you haven't called setAddDropList(List<TransactionAddDrop> addDropList) on addDropAdapter, so addDropList in getCount() is still an empty array, so getCount() == 0, which is why you are seeing 0 being displayed.
So, you need to find where you call addDropAdapter.setAddDropList() and then call getTotalCount.setText(""+addDropListView.getCount()); right after in order to update the total number of rows.
I have a BaseAdapter in that, I have a Button. When a user clicks on that button, I need to call a Service and I need to set the data to that button in onpostExecute()
public class MenuTagsAdapter extends BaseAdapter {
View v;
#Override
public int getCount() {
// TODO Auto-generated method stub
return BaseApp.getTagsAroundMeList().size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = layoutInflater.inflate(R.layout.menutaglistitem, null);
TextView textViewName = (TextView) v
.findViewById(R.id.textViewName);
final Button buttonAction = (Button) v
.findViewById(R.id.buttonAction);
textViewName.setText("#"
+ BaseApp.getTagsAroundMeList().get(position).name);
buttonAction
.setText(BaseApp.getTagsAroundMeList().get(position).action);
buttonAction.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (buttonAction.getText().toString()
.equalsIgnoreCase("follow")) {
buttonAction.setBackgroundResource(R.drawable.followbutton);
if (appUtils.getNetworkInfo(AmgonnaHome.this)) {
new FollowInterestAsyTask().execute();
} else {
NetworkDialogClass.createDAlertDialog(
AmgonnaHome.this,
getString(R.string.network_error));
}
} else {
buttonAction.setBackgroundResource(R.drawable.unfollowbutton);
if (appUtils.getNetworkInfo(AmgonnaHome.this)) {
new UnfollowInterestAsyTask().execute();
} else {
NetworkDialogClass.createDAlertDialog(
AmgonnaHome.this,
getString(R.string.network_error));
}
}
}
});
return v;
}
}
public class FollowInterestAsyTask extends AsyncTask<Void, Void, Void> {
boolean progressDialogStatus = true;
#Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(AmgonnaHome.this,
"Please Wait", "Connecting to Server");
progressDialog.setOnCancelListener(new OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
progressDialogStatus = false;
}
});
}
#Override
protected Void doInBackground(Void... params) {
TaskUrl = BaseApp.baseUrl + BaseApp.followInterest;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("user_id=" + amgonnaUserId);
// stringBuilder.append("&interestName="+);
stringBuilder.append("&interestName=");
ConnectionManager connectionManager = new ConnectionManager();
String response = connectionManager.setUpHttpPost(TaskUrl,
stringBuilder.toString());
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
errStatus = jsonObject.getInt("errStatus");
status = jsonObject.getString("status");
} catch (Exception e) {
// TODO: handle exception
}
}
return null;
}
#Override
protected void onPostExecute(Void result) {
if (progressDialogStatus) {
progressDialog.dismiss();
if (errStatus == 0) {
// here i need to set the status message to button on adapter list item
}
}
}
}
Just save the string you want to show in button in a variable.
eg :
String temp=btnText;
Then call your list adapter again.
And make a change in your getView() as
buttonAction.setText(temp);