0

I have a structure made from ListView - Customised as seen in Image Below Custom List Stucture

I can add New Products on Click of AddProduct Button A new Category gets added with EditText of Product and Quantity On that I have a (+) and (-) button which adds subcategory for Enter Dealer and Quantity with remove button on it .

The structure has been good .

But the data maintenance on it difficult . Like when I scroll , the focus gets lost and the data goes else where on ListView .

Kindly suggest some code for this .

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

I suggest to you to change the navigation structure. You can keep the delete feature on the listView maybe implementing the swipe as it happens for example in GMail. I would remove the add button and use FAB (Floating action Button) as Material guide lines suggest. Hope it will help you!

FrancescoAzzola
  • 2,666
  • 2
  • 15
  • 22
  • Thanks for help . But I need help while entering text inside the EditText and maintain it while deleting , scrolling the listview –  Oct 21 '15 at 11:19
  • 1
    I think `add` and `delete` will working fine as you are saying. Its new style to use and also user friendly. But He is may be stuck with saving data of each `EditText` Dynamically. – Pratik Butani Oct 21 '15 at 11:19
  • @PratikButani : yep , you got me –  Oct 21 '15 at 11:20
0

I have implemented this thing with the following structure.

  1. First of all I have created Model class for maintain data of Product.
  2. I am saving data in JSONArray with collection of JSONObject of quantity added. (I have used JSON because I can save easily as a String in Preference.)
  3. In onCreate of Activity I am creating SparseArray of Saved Products from JSONArray like:

    try {
    
        JSONArray savedProdJSONArray = new JSONArray(productSharedPref.getString("productArray", new JSONArray().toString()));
    
        Log.i(TAG, "Saved ARRAY Count : " + productSharedPref.getInt("count", -1));
    
        for (int i = 0; i < savedProdJSONArray.length(); i++) {
            ProductItems tempPItems = new ProductItems();
            tempPItems.setProdId(savedProdJSONArray.getJSONObject(i).getInt("prod_id"));
            tempPItems.setProdQty(savedProdJSONArray.getJSONObject(i).getDouble("qty"));
            tempPItems.setProdName(savedProdJSONArray.getJSONObject(i).getString("name"));
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        Log.e(TAG, "Json Err variant:"+e.getLocalizedMessage());
    }
    
  4. Now in getView() of Adapter I am checking with current ProductId and Saved ProductId is matched. If it is then fill up EditText with saved data like:

        /** First check whether value of Saved product Array is >0 or not..*/
        ProductItems savedProdTemp = prodItemsSavedList.get(holder.prodId, null);
    
        if(savedProdTemp != null)
        {
            productQtyValue = savedProdTemp.getProdQty();
            holder.prodQtyView.setText(""+productQtyValue);
        } else {
            holder.prodQtyView.setText("");
        }
    
  5. Here you also have to addTextChangeListner for EditText to save data in ArrayList and then you have to Convert in JSONArray when Activity is Stop or Pause

I think it is little bit confusing but I thought it is only helps you. I tried many times to find out solution but didn't better than this.

Hope it will help you.

Welcomes you if you have any question. (Sorry If you found English Mistake :D)

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • Should I save this in JSON Array while I type in EditText ,since the issue comes during scrolling , deleting of child item of listview –  Oct 21 '15 at 12:52
  • What you are getting on Scrolling or Deleting? – Pratik Butani Oct 21 '15 at 13:07
  • Its like the data on entering text in EditText in ListView , the data stays on scrolling down after leaving the screen and then scrolling down and coming back the data may or may not be found on same EditText , it might go to some other EditText –  Oct 22 '15 at 07:03
  • I think it is because of you are adding `EditText` dynamically – Pratik Butani Oct 22 '15 at 07:05
  • Yes I am adding it dynamically –  Oct 22 '15 at 07:07
  • I have heard its a known problem in android and I need a good waythrough for it –  Oct 22 '15 at 07:08