Monday 15 July 2013

java - Android EditText in a ListView - Erratic / Unexpected results -


I'm working on a client / server application to a few months, for the final year project of my undergraduate degree , I am currently working on a ListView, which should show a list of products and the user will be allowed to enter the value representing the amount of that item in the stock. I took a good look at the scene and adapter but editing text I caused issues, I have spent many hours to answer and pressed stack overflow for similar problems, but I have found either The issue is not implemented or the issue is not resolved.

I almost am definitely a Risaiclr issue but root of the problem seems to indicate to me that the value entered in the edit text to be placed in several positions in my Hampap, not just one, And scrolling through the list causes most of all to happen, if not all the scenes are to show the same value! Here's my adapter class and I'm happy to provide any other code that helps you, thank you in advance.

  Public class StockAdapter ArrayAdapter and lt; Stock & gt; {Private Layouts Inflator MLoot Infolator; Reference Reference; Int LayoutsreshsID; Stock data [] = null; Maps & lt; Integer, string & gt; Stockhashmap = new hashmop & lt; Integer, string & gt; (); Public stock adapters (reference references, int layasourceosource id, stock [] data) {super (references, layoutsresource id, data); MLayoutInflater = LayoutInflator From (context); This.context = context; This.layoutResourceId = layoutResourceId; This.data = data; } @Override Public View getView (last integer status, see convertView, ViewGroup parent) {Stockholder Holder = Null; If (convertView == empty) {convertView = mLayoutInflater.inflate (layoutResourceId, null); // Institution Stockholder Object Holder = New Stockholder (); // thoughts holder.txtName = (TextView) go to convertView.findViewById (R.id.stockName); Holder.etValue = (EditText) convertView.findViewById (R.id.etValue); ConvertView.setTag (holder); } And {holder = (Stockholder) ConvertView .getTag (); } // Get stock objects from the data set. Stock stock = data [status]; Holder.txtName.setText (stock.Name); // Keep the Stock ID in a variable - The last IID = Share is used to refer to the correct stock item. Id; String old text = stockhashmap.it; // Check whether the value of the old text is zero holder. Text (old text == empty? "": Old text); // Create the EditText addTextChangedListener (New TextWatcher (for holder.etValue.addTextChangedListener) {public void afterTextChanged (editable editable) {stockHashMap.put (ID, editable.toString ());} public void beforeTextChanged (CharSequence s, start int, int count, after rounding) {// TODO auto-generated method stub} public void onTextChanged (CharSequence s, int start, before int, int count) {// TODO auto-generated method stub}}); Return Convertview; } Fixed class stockholder {int id; TextView txtName; EditText at Value; }}   

Answer: Matt C. Answer:. The following but no better

  @Override public integer getCount () {if (data == null added) return 0; Return data Length; } @ Override public stock holidays (status of int) {return data [status]; }    

I if personally found I do not override function in an adapter I get all kinds of strange unexplained issues In your case, I think I will do a redundancy check and then return the size of the stock [] named "data". I can not guarantee that this will fix your problem, but for me in these cases, always "OK" you can also override for perfection.

No comments:

Post a Comment