Deleting an Item from Listview by Clicking on ImageView widget - android

I'm trying to delete an item from ListView by Clicking on a picture (imageView). I must do it this way, I've managed to do it by click on the item itself but for this project I'm not allowed to do that.
My Adapter extends BaseAdapter and my TaskListItem extends Relative Layout
I'm using a custom layout xml.
protected void onFinishInflate() {
super.onFinishInflate();
textV = (TextView)findViewById(R.id.textViewTask);
textP = ((TextView)findViewById(R.id.textPriority));
textR = ((TextView)findViewById(R.id.textResponsible));
imageD = ((ImageView)findViewById(R.id.imageDeleteTask));
imageD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
deleteTask();
}
});
}
and the deleteTask() method:
protected void deleteTask() {
//MainActivity.adapter.clear(position)
Toast.makeText(getContext(), "Task Deleted", Toast.LENGTH_SHORT).show();
MainActivity.adapter.notifyDataSetChanged();
}
my problem is the variable position. I cannot find a way to get the position of the item selected (by clicking on the imageView widget).
Finally, here's my adapter code. Any help will be much appreciated:
public class TaskListAdapter extends BaseAdapter {
private ArrayList<Task> tasks;
private Context context;
public TaskListAdapter(ArrayList<Task> tasks, Context context) {
super();
this.tasks = tasks;
this.context = context;
}
#Override
public int getCount() {
return tasks.size();
}
#Override
public Task getItem(int position) {
return (null==tasks)? null: tasks.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TaskListItem tli;
Log.v("test","dasfsd");
if (null == convertView) {
tli = (TaskListItem)View.inflate(context, R.layout.task_list_item, null);
}
else {
tli = (TaskListItem)convertView;
}
tli.setTask(tasks.get(position));
return tli;
}
public void forceReload() {
notifyDataSetChanged();
}
public void clear(int position) {
tasks.remove(position);
}
Update Code for OnClickListener on ImageView
public void setTask(final Task task) {
this.task = task;
//textV.set(task.isComplete());
textV.setText(task.getName());
textP.setText(task.getPriority());
textR.setText(task.getResponsible());
imageD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// probably get position
// deleteTask();
MainActivity.adapter.notifyDataSetChanged();
}
});
}
protected void deleteTask() {
int position=0;
MainActivity.adapter.clear(position);
Toast.makeText(getContext(), "Task Deleted", Toast.LENGTH_SHORT).show();
MainActivity.adapter.notifyDataSetChanged();
//testing - problem cannot delete item.
}

To get position , Add position as Tag of view
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TaskListItem tli;
Log.v("test","dasfsd");
if (null == convertView) {
tli = (TaskListItem)View.inflate(context, R.layout.task_list_item, null);
}else {
tli = (TaskListItem)convertView;
}
tli.setTask(tasks.get(position) , position);
return tli;
}
public void setTask(final Task task , int position) {
this.task = task;
//textV.set(task.isComplete());
textV.setText(task.getName());
textP.setText(task.getPriority());
textR.setText(task.getResponsible());
imageD.setTag(new Integer(position));
imageD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = (Integer) v.getTag();
deleteTask(position);
MainActivity.adapter.notifyDataSetChanged();
}
});
}
protected void deleteTask(int position) {
MainActivity.adapter.clear(position);
Toast.makeText(getContext(), "Task Deleted", Toast.LENGTH_SHORT).show();
MainActivity.adapter.notifyDataSetChanged();
//testing - problem cannot delete item.
}

Related

how to change position of textview with change the textview color

Hey new in android just create an app in that change the text color after change position of the in list view, when I am changing the position of the ABC at the same time change the new position ABC "Assigning" to "Assigned" text with change Assigned color red.
please help me.
private class CurrentEmployeeAdapter extends BaseAdapter {
Context context;
int layoutId;
LayoutInflater liCurrentEmp;
public CurrentEmployeeAdapter(CurrentEmployee currentEmployee, int activity_current_employee) {
this.context=currentEmployee;
this.layoutId=activity_current_employee;
liCurrentEmp=LayoutInflater.from(context);
}
#Override
public int getCount() {
return SalesManNameArrayList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View v;
if (convertView==null){
convertView=liCurrentEmp.inflate(R.layout.current_employee_items,parent,false);
v=convertView;
}else {
v=convertView;
}
TextView tvEmpName=(TextView)v.findViewById(R.id.tv_salesman_name);
final TextView tvassingwork=(TextView)v.findViewById(R.id.tv_assign_word);
Button btnAssign=(Button)v.findViewById(R.id.btn_assign);
btnAssign.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
tvassingwork.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (assignNo==1) {
tvassingwork.setText("Assigning");
tvassingwork.setTextColor(getResources().getColor(R.color.green));
assignNo=0;
}else {
int i=position+1;
if(i >0) {
String moveName = SalesManNameArrayList.get(position);
SalesManNameArrayList.set(position, SalesManNameArrayList.get(position));
SalesManNameArrayList.remove(position);
SalesManNameArrayList.add(SalesManNameArrayList.size(), moveName);
tvassingwork.setText("Assigned");
tvassingwork.setTag(position-1);
tvassingwork.setTextColor(getResources().getColor(R.color.red));
assignNo=1;
notifyDataSetChanged();
}
}
}
});
tvEmpName.setText(SalesManNameArrayList.get(position));
return convertView;
}
}
Try this
tvassingwork.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (assignNo==1) {
tvassingwork.setText("Assigning");
tvassingwork.setTextColor(getResources().getColor(R.color.green));
assignNo=0;
}else {
int i=position+1;
if(i >0) {
String moveName = SalesManNameArrayList.get(position);
SalesManNameArrayList.set(position, SalesManNameArrayList.get(position));
SalesManNameArrayList.remove(position);
SalesManNameArrayList.add(SalesManNameArrayList.size(), moveName);
tvassingwork.setText("Assigned");
tvassingwork.setTag(position-1);
tvassingwork.setTextColor(getResources().getColor(R.color.red));
assignNo=1;
notifyDataSetChanged();
}
}
});
}
});
runOnUIThread() may helps you.

How to change text of child view onclick of recycler view?

I have it clicked and it gets up to it and shows the right getText() method but the setText method is not working...
userAdapter.setOnEntryClickListener(new UserAdapter.OnEntryClickListener() {
#Override
public void onEntryClick(View view, int position) {
DatabaseUser user = dbUsersList.get(position);
TextView clickedView = (TextView) view.findViewById(R.id.userAdapterFollowBtn);
if(view == clickedView) {
if (clickedView.getText().equals("following")) {
Log.d(Constants.DEBUG, " THE CLICK VIEW IS " + clickedView.getText());
//APPLY Following
String txtFollow = "follow";
clickedView.setText(txtFollow);
if (user.getIsChanged() == 0) {
user.setIsChanged(1);
} else {
user.setIsChanged(0);
}
user.setIsType(3);
db.updateFollow(user);
userAdapter.notifyDataSetChanged();
} else {
clickedView.setText("following");
if (user.getIsChanged() == 0) {
user.setIsChanged(1);
} else {
user.setIsChanged(0);
}
user.setIsType(0);
db.updateFollow(user);
userAdapter.notifyDataSetChanged();
}
} else {
Toast.makeText(getApplicationContext(), user.getUsername() + " is selected!", Toast.LENGTH_SHORT).show();
takeToUserProfile(dbUsersList.get(position));
}
}
});
Here is the adapter class:
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.MyViewHolder> {
private List<DatabaseUser> dbUsersList, followingList;
private DatabaseHelper db;
private Context context;
private Typeface typeFace, italicTypeface, boldTypeface;
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView userAdapterUsername, userAdapterFollowBtn;
public ImageView userAdapterUserPicture;
public MyViewHolder(View view) {
super(view);
userAdapterUsername = (TextView) view.findViewById(R.id.userAdapterUsername);
userAdapterFollowBtn = (TextView) view.findViewById(R.id.userAdapterFollowBtn);
userAdapterUserPicture = (ImageView) view.findViewById(R.id.userAdapterUserPicture);
Log.d(Constants.DEBUG, "IN MY VIEW HOLDER");
view.setOnClickListener(this);
userAdapterFollowBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (mOnEntryClickListener != null) {
Log.d(Constants.DEBUG, "IN On click");
mOnEntryClickListener.onEntryClick(v, getAdapterPosition());
}
}
}
private static OnEntryClickListener mOnEntryClickListener;
public interface OnEntryClickListener {
void onEntryClick(View view, int position);
}
public void setOnEntryClickListener(OnEntryClickListener onEntryClickListener) {
mOnEntryClickListener = onEntryClickListener;
}
public UserAdapter(Context mContext, List<DatabaseUser> usersList, List<DatabaseUser> passedFollowing, Typeface myTypeface, Typeface myTypefaceItalic, Typeface myTypefaceBold) {
context = mContext;
dbUsersList = usersList;
followingList = passedFollowing;
typeFace = myTypeface;
italicTypeface = myTypefaceItalic;
boldTypeface = myTypefaceBold;
Log.d(Constants.DEBUG, "IN MY User ADAPTER CONSTRUCTOR");
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.follow_item, parent, false);
Log.d(Constants.DEBUG, "RETURN ITEM VIEW HOLDER");
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
DatabaseUser user = dbUsersList.get(position);
holder.userAdapterUsername.setTypeface(boldTypeface);
holder.userAdapterUsername.setText(user.getUsername());
final int pos = getItemViewType(position);
//TODO Create pic link
if(containsId(dbUsersList.get(pos), followingList)) {
//Then show following
holder.userAdapterFollowBtn.setText("following");
} else {
//show follow
holder.userAdapterFollowBtn.setText("follow");
}
String userspic = dbUsersList.get(pos).getPicture();
if(userspic == null) {
//SET DEFAULT OR PUT DEFAULT IN XML AND DO NOTHING IT SHOULD SHOW DEFAULT PIC
} else {
//TODO setupUser Pic
String img1 = "http://www.hindustantimes.com/Images/popup/2015/6/kungfu2.jpg";
Picasso.with(context).load(img1).transform(new RoundedTransformation()).into(holder.userAdapterUserPicture);
}
}
#Override
public int getItemCount() {
return dbUsersList.size();
}
public static boolean containsId(DatabaseUser currentUser, List<DatabaseUser> list) {
for (DatabaseUser object : list) {
if (currentUser.getUserId().equals(object.getUserId())) {
return true;
}
}
return false;
}
#Override
public int getItemViewType(int position) {
return position;
}
}
your dbUsersList is not updating. please check your user object in dbUsersList after notify data set change.
What ended up being the problem is that I had passed in the followingList, so I never re-called to grab the new following from the db on update. The update was happening I just had to re-grab the followingList from the db to have an updated list to check against like so in a new method that was passing the list back to the contains method.
db.grabFollowersList();

Set text to TextView at a particular position inside a ListView

I am using a ListView with a custom Adapter. I have two TextView inside each row. I need to change the text of these TextView only for the textViews which I click. How can I achieve it?
I have a method inside my CustomAdapter where I initialise the TextView's
public class MainListAdapter extends BaseAdapter {
private static final String TAG = "MainListAdapter";
private Context mContext;
private LayoutInflater layoutInflater;
private MyViewPager itemViewPager;
private View viewMain;
private View viewSlide;
private TextView cancel;
private TextView delete, block;
TextView itemName, showResult;
int triedOnce;
private ArrayList<View> views;
private PagerAdapter pagerAdapter;
private ArrayList<String> mList;
public static final String API_KEY = "MYAPIKEY";
public MainListAdapter(Context context, ArrayList<String> list) {
mContext = context;
layoutInflater = LayoutInflater.from(mContext);
mList = list;
}
#Override
public int getCount() {
return mList != null ? mList.size() : 0;
}
#Override
public Object getItem(int position) {
return mList != null ? mList.get(position) : null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.listview_item, null);
}
if(position%2 == 0){
convertView.setBackgroundResource(R.drawable.lis_bg);
}else if(position%2 == 1){
convertView.setBackgroundResource(R.drawable.ls_eppadi_bg);
}
viewMain = layoutInflater.inflate(R.layout.listview_item_main, null);
viewSlide = layoutInflater.inflate(R.layout.listview_item_slide, null);
cancel = (TextView)viewSlide.findViewById(R.id.tv_menu_cancel);
delete = (TextView)viewSlide.findViewById(R.id.tv_menu_delete);
block = (TextView) viewSlide.findViewById(R.id.tv_menu_block);
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//perform cancel
}
});
delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//perform delete
}
});
block.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//perform block
}
});
views = new ArrayList<View>();
views.add(viewMain);
views.add(viewSlide);
itemViewPager = (MyViewPager)convertView.findViewById(R.id.vp_list_item);
itemViewPager.setSelfIndex(position);
pagerAdapter = new PagerAdapter() {
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((MyViewPager)container).removeView(views.get(position));
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
((MyViewPager)container).addView(views.get(position));
return views.get(position);
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
#Override
public int getCount() {
return views.size();
}
};
fillItemData(convertView, position, viewMain);
itemViewPager.setAdapter(pagerAdapter);
itemViewPager.setCurrentItem(0);
return convertView;
}
//this is where the textview's are initialised
private void fillItemData(View convertView, final int position, View viewMain) {
int[] colorCollection = {
R.color.green, R.color.royalblue, R.color.violet
};
for (int i = 0; i < colorCollection.length; i++) {
colorCollection[i] = mContext.getResources().getColor(colorCollection[i]);
}
int currColor = colorCollection[position % colorCollection.length];
itemName = (TextView)viewMain.findViewById(R.id.tv_item_name);
showResult = (TextView)viewMain.findViewById(R.id.tv_show);
itemName.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
new PushTask().execute(position);
triedOnce = 0;
}
});
itemName.setBackgroundColor(currColor);
showResult.setBackgroundColor(currColor);
itemName.setText(mList.get(position));
}
class PushTask extends AsyncTask<Integer, Integer, Integer> {
#Override
protected void onPreExecute() {
itemName.setVisibility(View.GONE);
showResult.setVisibility(View.VISIBLE);
//set text here based on the position
showResult.setText("SENDING");
}
#Override
protected Integer doInBackground(Integer... position) {
int post = position[0];
int respCode = 0;
//perform my network operations
return respCode;
}
#Override
protected void onPostExecute(Integer response) {
switch(response) {
case 1:
//set text here
showResult.setText("SENT");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
showResult.setVisibility(View.GONE);
itemName.setVisibility(View.VISIBLE);
}
}, 2000);
break;
case 2:
//set text here
showResult.setText("PLEASE WAIT!");
handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
showResult.setVisibility(View.GONE);
itemName.setVisibility(View.VISIBLE);
}
}, 2000);
break;
case 3:
//set text here
showResult.setText("FAILED!");
handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
showResult.setVisibility(View.GONE);
itemName.setVisibility(View.VISIBLE);
}
}, 2000);
break;
case 4:
//set text here
showResult.setText("FAILED!");
handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
showResult.setVisibility(View.GONE);
itemName.setVisibility(View.VISIBLE);
}
}, 2000);
break;
default:
break;
}
}
}
}
Now I need to change the itemName and showResult's text based on the position where the user clicks. The itemName.setOnClickListener has the AsyncTask where I will changing the text of these textViews.
Currently it changes for the last row of the listView.
How do I change it for the position selected.
Thanks in advance.
Override the getView(...) function of CustomAdapter,where one of the arguments is int position .
Don't forget to use convertView, holder and settag/gettag for smooth scrolling and correct references
Update:
in getView put:
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//perform update on textView here
}
});
Also we need reference of convertView in postExecute(). You can pass this reference in AsycTask arguments or set getter setter for the adapter and get clicked reference in asyctask postexecute()
create a model(POJO) class first
with your two strings and one boolean value call it as isChecked
add getters and setters to it
set values(list data) to your arraylist and keep setIsChecked value to false for the first time. like this
ArrayList<model> list = new ArrayList<model>();
list.add(new model("string1","string2",false);
list.add(new model("string11","string22",false);
and so on
now onItemClickListener use for loop like this
for(int i = 0 ; i < list.size; i++){
list.get(i).setIsChecked(false);
}
list.get(itemClickedPosition).setIsChecked(true);
youradapter.notifyDataSetChanged();
after that now come to the adapter class where you can set the selected textview as you want do like this
in getView method do this
if(list.get(position).getIsChecked()){
change your textview
}else{
leave as it is
}
done let me know if it helps you
Pass View in Async Task and then convert into textView and SetText in DoInBackground Method.
new PushTask().execute(v);
#Override
protected Integer doInBackground(final View position) {
runOnUiThread(new Runnable() {
public void run() {
// some code #3 (Write your code here to run in UI thread)
TextView txtName=(TextView)position;
txtname.setText(“android”):
}
});
}

How do I get a reference to the layout of the specific row I was touching?

I've created a custom adapter. Now, I would like to fade out a specific row layout when the user clicks the "cancel" button. The problem is I get only the last row created to fade out and not the row I was actually pressing in:
public class SwipeableRequestsAdapter extends SwipeAdapter {
private final Context ctx;
private final Followers[] values;
private final Typeface roboto;
private ImageView check;
private ImageView cancel;
private SwipeLayout swipeLayout;
public SwipeableRequestsAdapter(Context context, Followers[] items) {
ctx = context;
values = items;
roboto = Typeface.createFromAsset(ctx.getAssets(), "roboto_thin.ttf");
}
#Override
public int getSwipeLayoutResourceId(int position) {
return R.id.swipe;
}
#Override
public View generateView(int i, ViewGroup viewGroup) {
return LayoutInflater.from(ctx).inflate(R.layout.grid_item, null);
}
#Override
public void fillValues(int i, View view) {
swipeLayout = (SwipeLayout) view.findViewById(R.id.swipe);
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
#Override
public void onClose(SwipeLayout swipeLayout) {
}
#Override
public void onUpdate(SwipeLayout swipeLayout, int i, int i2) {
}
#Override
public void onOpen(SwipeLayout swipeLayout) {
}
#Override
public void onHandRelease(SwipeLayout swipeLayout, float v, float v2) {
}
});
TextView requestText = (TextView) view.findViewById(R.id.sender);
requestText.setTypeface(roboto);
TextView requestPhone = (TextView) view.findViewById(R.id.phone);
requestPhone.setTypeface(roboto);
requestPhone.setText(values[i].getNumber_sender());
TextView currentState = (TextView) view.findViewById(R.id.currentState);
currentState.setTypeface(roboto);
TextView stateTitle = (TextView) view.findViewById(R.id.state);
stateTitle.setTypeface(roboto);
String state = values[i].getState();
if (state.equals("0")) {
currentState.setText("Pending");
} else if (state.equals("1")) {
currentState.setText("Accepted");
} else if (state.equals("2")) {
currentState.setText("Rejected");
} else if (state.equals("3")) {
currentState.setText("Track Back");
}
check = (ImageView) view.findViewById(R.id.approve);
check.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
scaleEffect(v);
Toast.makeText(ctx, "Approved", Toast.LENGTH_SHORT).show();
}
});
cancel = (ImageView) view.findViewById(R.id.trash);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
scaleEffect(v);
swipeLayout.animate().alpha(0f).setDuration(150).start();
Toast.makeText(ctx, "Canceled", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getCount() {
return values.length;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
private void scaleEffect(final View view) {
view.setScaleX(1.5f);
view.setScaleY(1.5f);
new Thread(new Runnable() {
#Override
public void run() {
try {
Thread.sleep(100);
view.post(new Runnable() {
#Override
public void run() {
view.setScaleX(1f);
view.setScaleY(1f);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
Yes!!! I've found the solution!
All I had to do was to climb up the view hierarchy - inside the list item I already set a button listener:
cancel = (ImageView) view.findViewById(R.id.trash);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {}
But now that I have the reference for that specific button through the View passed to the onClick - "v", I can ask to get it's parent view. Anyway, the complete code looks like this:
cancel = (ImageView) view.findViewById(R.id.trash);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
scaleEffect(v);
LinearLayout a = (LinearLayout) v.getParent();
SwipeLayout parent = (SwipeLayout) a.getParent();
parent.animate().alpha(0f).setDuration(300).start();
Toast.makeText(ctx, "Canceled", Toast.LENGTH_SHORT).show();
}
});

Progress dialog not showing in button click event in listview

I have a button in each list item of list view. In that button click event i have some codes to run. In click event im showing the progress dialog before the code runs. but its not getting shown. After all the codes in click event completes in the end progress dialog gets shown. Plz help me.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
TheListViewM = (ListView) findViewById(R.id.lvItems);
ImageAdapter anImageAdapterM =new ImageAdapter(this);
TheListViewM.setAdapter(anImageAdapterM);
}
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
if (ConvertViewP == null) {
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
}
TextView textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
textView1.setText("asdfg");
final Spinner spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spQuantity.setAdapter(QuantityAdapter1);
Button btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
Try this one.
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
class ViewHolder {
Button btn1;
TextView textView1;
Spinner spQuantity;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
ViewHolder holder;
if (ConvertViewP == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
holder.textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
holder.spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
holder.btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
ConvertViewP.setTag(holder);
}
else{
holder = (ViewHolder) ConvertViewP.getTag();
}
holder.textView1.setText("asdfg");
holder.spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spQuantity.setAdapter(QuantityAdapter1);
holder.btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
}

Categories

Resources