OnClickListener on button inside nested ListViews - android

I'm trying to create a news feed with comments in Android. I'm using a CursorAdapter with a ListView to implement both the news feed and the list of comments on each item. However, I have no idea how to get the text from the correct EditText when the corresponding Button is pressed.
The only thing I'm really sure about is that I'm doing this wrong.
W/View﹕ requestLayout() improperly called by android.widget.ListView{41e85210 V.ED.VC. ......I. 9,71-711,221 #7f07004a app:id/comments} during layout: running second layout pass
Note: the code below obviously doesn't work, since I'm using only one variable commentText for all rows.
database.getComments() returns a Cursor.
database.addUploadComment() just does an sql insert to save the newly created comment.
public class TimelineCursorAdapter extends CursorAdapter {
public TimelineCursorAdapter(Context context, Cursor cursor, boolean autoRequery) {
super(context, cursor, autoRequery);
}
private TimelineCommentCursorAdapter timelineCommentCursorAdapter;
#Override
public View newView(Context context, final Cursor cursor, ViewGroup parent) {
// when the view will be created for first time,
// we need to tell the adapters, how each item will look
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View returnView = inflater.inflate(R.layout.timeline_item, parent, false);
Log.v(this.getClass().getSimpleName(), "newView called");
// get comments
Database database = Database.getDatabase(context);
timelineCommentCursorAdapter = new TimelineCommentCursorAdapter(context, database.getComments(cursor.getInt(cursor.getColumnIndex("_id"))), true);
ListView listView = (ListView) returnView.findViewById(R.id.comments);
listView.setAdapter(timelineCommentCursorAdapter);
Log.d(this.getClass().getSimpleName(), "adapter: " + listView.getAdapter().toString());
returnView.findViewById(R.id.commentText).setTag(cursor.getPosition());
return returnView;
}
EditText commentText;
#Override
public void bindView(View view, Context context, Cursor cursor) {
Log.v(this.getClass().getSimpleName(), "bindView called");
// here we are setting our data
// that means, take the data from the cursor and put it in views
TextView username = (TextView) view.findViewById(R.id.username);
String usernameString = cursor.getString(cursor.getColumnIndex("username"));
if (usernameString != null) {
username.setText(usernameString);
}
TextView status = (TextView) view.findViewById(R.id.status);
String statusString = cursor.getString(cursor.getColumnIndex("bodytext"));
if (statusString != null) {
status.setText(statusString);
}
TextView timestamp = (TextView) view.findViewById(R.id.timestamp);
String timestampString = cursor.getString(cursor.getColumnIndex("datetime"));
if (timestampString != null) {
timestamp.setText(timestampString);
}
// update the comments section as well
Database database = Database.getDatabase(context);
timelineCommentCursorAdapter.changeCursor(database.getComments(cursor.getInt(cursor.getColumnIndex("_id"))));
Log.v(TimelineCursorAdapter.class.getSimpleName(), "commentButton getView");
Button commentButton = (Button) view.findViewById(R.id.commentButton);
commentText = (EditText) view.findViewById(R.id.commentText);
commentButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v(TimelineCursorAdapter.class.getSimpleName(), "commentButton onClick");
Log.e("POTATO", view.toString());
Database database = Database.getDatabase(view.getContext());
database.addUploadComment(commentText.getText().toString(), (Integer) commentText.getTag());
commentText.setText("");
}
});
}
Just ask if you need some more code.

Related

ListViewAnimations only works when the Listview has only 1 view/element

I am using ListViewAnimations I am having this weird problem,
the animation is skipped and all of the views are populated if the list contains more than 1 element, but animation works if there is only one element to populate.
class AdapterOutcome extends CursorAdapter {
public AdapterOutcome(Context context, Cursor c, int flags) {
super(context, c, 0);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.outcome_custom_row, parent, false);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
//finding the Views
TextView amonut = (TextView) view.findViewById(R.id.amount);
ImageView transactionType = (ImageView) view.findViewById(R.id.custom_row_icon);
TextView time = (TextView) view.findViewById(R.id.timeid);
TextView location = (TextView) view.findViewById(R.id.location);
TextView date = (TextView) view.findViewById(R.id.date);
TextView type_icon = (TextView) view.findViewById(R.id.type_icon);
//Creating Cursors for each View
String cursorTranscationType = cursor.getString(cursor.getColumnIndexOrThrow("_transactionType"));
String cursorAmount = cursor.getString(cursor.getColumnIndexOrThrow("_amount"));
String cursorTime = cursor.getString(cursor.getColumnIndexOrThrow("_time"));
String cursorLocation = cursor.getString(cursor.getColumnIndexOrThrow("_location"));
String cursorDay = cursor.getString(cursor.getColumnIndexOrThrow("_day"));
String cursorMonth = cursor.getString(cursor.getColumnIndexOrThrow("_month"));
String cursorYear = cursor.getString(cursor.getColumnIndexOrThrow("_year"));
DateFormat dateformat = DateFormat.getDateInstance(DateFormat.MEDIUM);
// Date myDate = new Date(Integer.parseInt(cursorYear)-1900, Integer.parseInt(cursorMonth)-1, Integer.parseInt(cursorDay));
//set the data from the Cursor to the Views
amonut.setText(String.valueOf("- " + cursorAmount));
time.setText(String.valueOf(cursorTime));
location.setText(String.valueOf(cursorLocation));
// date.setText( dateformat.format(myDate));
if (cursorTranscationType.equals("Purchase")) {
type_icon.setText("P");
}
else{
type_icon.setText("C");
}
}
}
Did you use a custom adapter for your list view? if yes, save the last position of your getView in a global int variable and when next a view need to be populated, use the last position.
if this is not clear enough, post a sample of your code.

Dynamically Add/Remove View CursorAdapter according with Data Value

I have a Cursor Adapter and I want to display a button and a TextView only if the value of a field (accessed from cursor) is between 1 and 4, if not, this views are removed.
So, I created a LayoutFile, with this views, and in CursorAdapter, I check if the field accessed from cursor is between 1 and 4, I remove the Views, otherwise, I add to the Layout:
class Accounts_List_CursorAdapter extends CursorAdapter{
//
Context context;
//
public Accounts_List_CursorAdapter(Context context, Cursor c) {
super(context, c, 0);
this.context = context;
}
#Override
//
//Inflate layout of the rows
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.row_list_accounts_data, parent, false);
}
#Override
//
//Set data and set changes to the row
public void bindView(View view, final Context context, Cursor cursor) {
//
//Find the elements
RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.layoutRowListAccountsData);
TextView tvAccountsName = (TextView) view.findViewById(R.id.tvAccountsName);
TextView tvAccountsInitValue = (TextView) view.findViewById(R.id.tvAccountsInitValue);
TextView tvAccountsType = (TextView) view.findViewById(R.id.tvAccountsType);
//
//Get data from cursor
final int accountId = cursor.getInt(cursor.getColumnIndexOrThrow(0));
final String accountsName = cursor.getString(cursor.getColumnIndexOrThrow(1));
final String accountsCurrValue = cursor.getString(cursor.getColumnIndexOrThrow(2));
final String accountsInitValue = cursor.getString(cursor.getColumnIndexOrThrow(3));
final String accountsType = cursor.getString(cursor.getColumnIndexOrThrow(4));
//
tvAccountsName.setText(accountsName);
tvAccountsCurrValue.setText("Current Value = " + accountsCurrValue);
//
if ((accountId >= 1) && (accountId <= 4)){
try {
relativeLayout.removeView(view.findViewById(R.id.cmdEditThisAccount));
relativeLayout.removeView(view.findViewById(R.id.tvAccountsInitValue));*
} catch (Exception e) {
e.printStackTrace();
}
}
else{
//
relativeLayout.addView(view.findViewById(R.id.cmdEditThisAccount));
relativeLayout.addView(view.findViewById(R.id.tvAccountsInitValue));
//
tvAccountsInitValue.setText("Init Value = " + accountsInitValue);
//
Button cmdEditThisAccount = (Button) view.findViewById(R.id.cmdEditThisAccount);
cmdEditThisAccount.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, UpdateAccount.class);
context.startActivity(intent);
}
});
}
}
}
The problem is: When I run this code, it comes out this message: Java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
What am I doing wrong, or there is another way to hide and show dynamically the TextView and Button from Layout, according with the data returned by cursor?
Thanks in Advance!
Use View.setVisibility(FLAG) i.e. view.findViewById(R.id.cmdEditThisAccount).setVisibility(View.GONE)
api doc

CursorAdapter changed style of SwipeMenuListView after scroll

I'm trying to develop an app to record debts in which I have a SwipeMenuListView from this github https://github.com/baoyongzhang/SwipeMenuListView for adding a swipe menu. Using a custom CursorAdapter, I populate the ListView with the name and total debt.
Now, I want to group each listview items depending on the due date. I've created a new column on my SQLite to add a header for each day. Now I just need to use different style for header and items of the ListView. By detecting the new column from bindView and depending on if it's a header or items, it will change, hide and show elements from the same layout.
The problem is that when I scroll the ListView, some of the listview items changed style. It get worse if I keep scrolling up and down. Here's the picture of the error from the listview. Notice that it's all in one session, the header style seems to have been used in some of the items and the header itself changed to red color which suppose to be color code for the items. If I click one of the item, it still get the correct item so I figure its a problem within the cursorAdapter but I just can't figure it out. It is not a mistake in the SQL database which I have checked.
Here's the cursorAdapter.
public class DebtCursorAdapterMain extends CursorAdapter {
public DebtCursorAdapterMain(Context context, Cursor c, int flags) {
super(context, c, flags);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.debt_list_item, parent, false);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
int x = Integer.parseInt(cursor.getString(cursor.getColumnIndex(DBHelper.DATE_SEPARATOR_COLUMN)));
TextView tvName = (TextView) view.findViewById(R.id.tvName);
TextView tvTotal = (TextView) view.findViewById(R.id.tvTotal);
if(x == 0) {
DecimalFormat df = new DecimalFormat("#.00");
String nameText = cursor.getString(cursor.getColumnIndex(DBHelper.NAME_COLUMN));
String totalText = "$ " + df.format(cursor.getDouble(cursor.getColumnIndex(DBHelper.TOTAL_COLUMN)));
String type = cursor.getString(cursor.getColumnIndex(DBHelper.TYPE_COLUMN));
if (tvName != null)
tvName.setText(nameText);
if (tvTotal != null)
tvTotal.setText(totalText);
if (type.equals("L"))
view.setBackgroundColor(Color.parseColor("#ff9999"));
if (type.equals("B"))
view.setBackgroundColor(Color.parseColor("#99ff99"));
}
if(x == 1){
String date = cursor.getString(cursor.getColumnIndex(DBHelper.DUE_DATE_COLUMN));
if (tvName != null && tvTotal != null) {
tvName.setText(date);
tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
tvTotal.setVisibility(View.GONE);
}
}
}
}
Here is the main activity in which the cursorAdapter is called.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find SwipeMenuListView
final SwipeMenuListView swipeMenuList = (SwipeMenuListView) findViewById(R.id.swipeMenuList);
// Create Debt database cursor adapter
cursorAdapter = new DebtCursorAdapterMain(this, null, 0);
// Create SwipeMenuList and set item
SwipeMenuCreator creator = createMainActivitySwipeMenu();
swipeMenuList.setMenuCreator(creator);
swipeMenuList.setAdapter(cursorAdapter);
swipeMenuList.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
// Set SwipeMenuList on item's menu click
swipeMenuList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
....
}
});
// Swipe menu on Click function
swipeMenuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
....
}
});
// Initialize cursor and check database for updating top info
getLoaderManager().initLoader(0, null, this);
checkDataBase();
}
I'm still new in android development so please tell me if there's a better approach to this problem. Thanks guys.

refresh listview after data has changed from custom adapter

I have seen several posts on this but I cannot seem to follow one well enough to fix my problem.
I am trying to refresh my ListView after I update or delete a record. I am currently using notifyDataSetChanged() however it does not refresh upon deletion. I can delete, and then if i back our and reload my history.java it will show the updates because I am reloading all of the data.
here is my HistoryAdapter.java
public class HistoryAdapter extends BaseAdapter {
private Context mContext;
Cursor cursor;
history historyClass = new history();
MySQLiteHelper db;
public HistoryAdapter(Context context, Cursor cur){
super();
mContext = context;
cursor = cur;
db = new MySQLiteHelper(context);
}
public int getCount(){
// return the number of records in cursor
return cursor.getCount();
}
// getView method is called for each item of ListView
public View getView(final int position, View view, ViewGroup parent){
// inflate the layout for each item of listView
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.history_list_item, null);
// move the cursor to required position
cursor.moveToPosition(position);
final String id = cursor.getString(cursor.getColumnIndex("_id"));
final long deleteId = Long.parseLong(id);
// fetch the information for each card
String pricePerGallon = cursor.getString(cursor.getColumnIndex("pricePerGallon"));
String gallons = cursor.getString(cursor.getColumnIndex("gallons"));
String odometer = cursor.getString(cursor.getColumnIndex("odometer"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String filledOrNot = cursor.getString(cursor.getColumnIndex("filledOrNot"));
String comments = cursor.getString(cursor.getColumnIndex("comments"));
//String milesPerGallon = cursor.getString(cursor.getColumnIndex("miledPerGallon"));
String totalSpent = cursor.getString(cursor.getColumnIndex("totalSpent"));
// get the reference of TextViews
TextView textViewPricePerGallon = (TextView) view.findViewById(R.id.cardPrice);
TextView textViewGallons = (TextView) view.findViewById(R.id.cardGallons);
TextView textViewOdometer = (TextView) view.findViewById(R.id.cardOdometer);
TextView textViewDate = (TextView) view.findViewById(R.id.cardDate);
TextView textViewFilledOrNot = (TextView) view.findViewById(R.id.cardFilledOrNot);
TextView textViewComments = (TextView) view.findViewById(R.id.cardComments);
//TextView textViewMilesPerGallon = (TextView) view.findViewById(R.id.mpg);
TextView textViewTotalSpent = (TextView) view.findViewById(R.id.usd);
TextView textViewDeleteButton = (TextView) view.findViewById(R.id.deleteButton);
// Set the data to each TextView
textViewPricePerGallon.setText(pricePerGallon);
textViewGallons.setText(gallons);
textViewOdometer.setText(odometer);
textViewDate.setText(date);
textViewFilledOrNot.setText(filledOrNot);
textViewComments.setText(comments);
//textViewMilesPerGallon.setText(milesPerGallon);
textViewTotalSpent.setText(totalSpent);
final HistoryAdapter historyAdapter = this;
textViewDeleteButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("History Adapter", "" + deleteId);
//need to delete here
deleteRecord(deleteId);
historyAdapter.notifyDataSetChanged();
}
});
return view;
}
public Object getItem(int position){
return position;
}
public long getItemId(int position){
return position;
}
private void deleteRecord(long id){
db.deleteGasLog(id);
}
}
here is my history.java which sets the adapter and creates the listview
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
context = this;
initViews();
cursor = db.getAllLogs();
// Create the Adapter
historyAdapter = new HistoryAdapter(this, cursor);
// Set the adapter to ListView
listContent.setAdapter(historyAdapter);
}
I guess you will need to get a new cursor.
Try moving this
cursor = db.getAllLogs();
into the adapter and call it again before the notifyDataSetChanged() call.
You are deleting the row but you are never updating or getting a new cursor, which has the result set the adapter uses to layout the list. You need to give the adapter a new cursor after you delete a row, then call notifyDatasetChanged(). If you use SimpleCursorAdapter
instead of BaseAdapter, you can use its swapCursor() method to set the new cursor.
Make sure to call:
registerDataSetObserver(...)
from your BaseAdapter subclass.
Pass it the reference to your DataSetObserver implementation. Possibly through an inner class of HistoryAdapter:
public class HistoryAdapter extends BaseAdapter {
. . .
public class MyDataSetObserver extends DataSetObserver {
public void onChanged() {
// Data Set changed.... do something...
}
public void onValidated() {
// Your implementation here
}
}
. . .
public HistoryAdapter(Context context, Cursor cur) {
. . .
registerDataSetObserver(new MyDataSetObserver());
. . .
}
}
HTH

EditText in ListView without it recycling input

Still new to android and even more to custom cursor adapter so I'm having trouble understanding how to prevent my listview from recycling views to prevent input from one edittext to show up in another when scrolled. I've seen on other post saying to change the name of convertview but how to do that I'm drawing a blank. I was hoping someone here would be able to give more details or example of how to do based of what code I've wrote so far.
public class editview extends ListActivity {
private dbadapter mydbhelper;
private PopupWindow pw;
public static int editCount;
public static ListView listView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mydbhelper = new dbadapter(this);
mydbhelper.open();
View footer = getLayoutInflater().inflate(R.layout.footer_layout, null);
ListView listView = getListView();
listView.addFooterView(footer);
showResults();
}
//Populate view
private void showResults (){
Cursor cursor = mydbhelper.getUserWord();
startManagingCursor(cursor);
String[] from = new String[] {dbadapter.KEY_USERWORD};
int[] to = new int[] {R.id.textType};
ItemAdapter adapter = new ItemAdapter(this, R.layout.edit_row, cursor,
from, to);
adapter.notifyDataSetChanged();
this.setListAdapter(adapter);
editCount = adapter.getCount();
}
//footer button
public void onClick(View footer){
final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
editClickSound.start();
startActivity(new Intent("wanted.pro.madlibs.OUTPUT"));
}
//custom cursor adapter
class ItemAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
private Cursor cursor;
public ItemAdapter(Context context, int layout, Cursor cursor, String[] from,
int[] to) {
super(context, layout, cursor, from, to);
this.cursor = cursor;
mInflater = LayoutInflater.from(context);
}
static class ViewHolder {
protected TextView text;
protected EditText edittext;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.edit_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.textType);
holder.edittext = (EditText) convertView.findViewById(R.id.editText);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
cursor.moveToPosition(position);
int label_index = cursor.getColumnIndex("userword");
String label = cursor.getString(label_index);
holder.text.setText(label);
return convertView;
}
}
Changed it to
class ItemAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
private Cursor cursor;
Map<Integer, String> inputValues = new HashMap<Integer, String>();
public View getView(final int position, View convertView, ViewGroup parent) {
....
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.edit_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.textType);
holder.edittext = (EditText) convertView.findViewById(R.id.editText);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
cursor.moveToPosition(position);
int label_index = cursor.getColumnIndex("userword");
String label = cursor.getString(label_index);
holder.text.setText(label);
String oldText = inputValues.get(position);
holder.edittext.setText(oldText == null ? "" : oldText);
holder.edittext.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable editable) {
inputValues.put(position, editable.toString());
}
but it is recycling after all edittext have data. Tried using holder.edittext.setText(oldText) but same effect.
First of all, you really don't want to prevent a list view from recycling its views. View recycling is a huge optimization. For a lot of really good info on lists, see the google IO talk: http://www.youtube.com/watch?v=wDBM6wVEO70
That being said, you've correctly identified your problem: You have far fewer EditTexts than you do items in your list. As the you scroll through the list those EditTexts are recycled so you see the same input over and over again.
Basically what you need to do is save the input for your EditTexts in some datastructure (a HashMap if they will only edit a few values, maybe a List if they will be changing most of the values, either would work) that maps the position to the input. You can do this by adding a textChangedListener to your edit texts in getView:
#Override
public View getView(final int position, View convertView, ViewGroup parent){
...
cursor.moveToPosition(position);
int label_index = cursor.getColumnIndex("userword");
String label = cursor.getString(label_index);
holder.text.setText(label);
//clear whatever text was there from some other position
//and set it to whatever text the user edited for the current
//position if available
String oldText = yourMapOfPositionsToValues.get(position);
holder.setText(oldText == null ? "" : oldText);
//every time the user adds/removes a character from the edit text, save
//the current value of the edit text to retrieve later
holder.edittext.addTextChangedListener(new TextWatcher(){
#Override
public void afterTextChanged(Editable editable) {
yourMapOfPositionsToValues.put(position, editable.toString());
}
....
};
return convertView;
}
Whenever your user is done editing, you can run through your datastructure and do whatever with those values.
Edit:
I changed onTextChanged to afterTextChanged because I've used that before and I know it works. Keep in mind that afterTextChanged is called every time a LETTER changes, not just after the user finishes typing a word. If the user types "dog" afterTextChanged will be called three times, first with 'd', then with 'do', then with 'dog'.
A HashMap is simple: Map yourMapOfPositionsToValues = new HashMap();
to add or update an item: yourMap.put(position, someText);
to fetch an item: yourMap.get(position);
if hashmaps don't make sense, spend some time researching them. They are an incredibly important data structure.
Your TextWatcher implementation is incorrect. Your data structure should not belong to a single view, but rather the activity or your adapter. It appears to you that positions aren't stable because your List is owned by each view. The positions themselves are stable in that unless the underlying data changes the cursor will return the same data every time for the same position. However, the edit text is used for multiple different positions.
Create a hashmap as an instance variable I demonstrated above in the constructor of your adapter. Then add exactly the TextWatcher I wrote originally, no need for a named class, anonymous is simpler. Your code should work.
The solution to this is removing the added textwatcher before setting the text. Otherwise, the previous textwatcher on that view will still be called along with the new textwatcher. Store the textwatcher as a tag on the EditText to keep track of it.
Object oldWatcher = viewHolder.quantitySold.getTag();
if(oldWatcher != null){
viewHolder.quantitySold.removeTextChangedListener((CustomTextWatcher)oldWatcher);
}
String oldText = inputValues.get("key"+position);
Log.d(TAG, "oldText: "+oldText+" position: "+position);
viewHolder.quantitySold.setText(oldText == null ? "" : oldText);
CustomTextWatcher watcher = new CustomTextWatcher(
cursor.getString(SKUFragment.COL_NAME),
cursor.getInt(SKUFragment.COL_ID),
cursor.getDouble(SKUFragment.COL_UNIT_PRICE),
position
) {
#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 (s != null) {
int quantity = 0;
if (!TextUtils.isEmpty(s.toString())) {
quantity = Integer.parseInt(s.toString());
inputValues.put("key"+mPosition, "" + quantity);
}else{
inputValues.put("key"+mPosition, "");
}
double value = quantity * skuPrice;
mListener.onQuantityChanged(skuName+", position: "+mPosition, skuId, quantity, value);
}
}
};
viewHolder.quantitySold.setTag(watcher);
viewHolder.quantitySold.addTextChangedListener(watcher);

Categories

Resources