-2

I have searched a lot in SO, but didn't get similar type thread. In my application, i need to add or remove item in activity's layout when user clicks on listview's item. Listview displays data using a custom array adapter. If user clicks on an item then it will be added to the activity's layout and further clicks on the same item, it will be removed. I don't know how to accomplish this task. Any help will be appreciated in this context.

Here is an image:

enter image description here

godot
  • 3,422
  • 6
  • 25
  • 42
Dev b
  • 17
  • 6
  • 3
    Possible duplicate of [How to add/remove item from listview in android when click button in item listview](https://stackoverflow.com/questions/13412341/how-to-add-remove-item-from-listview-in-android-when-click-button-in-item-listvi) –  Mar 13 '18 at 13:25
  • Perform Add/Remove Operation in `ArrayList` and update adapter with `notifyDataSetChanged()`. – Pragnesh Ghoda シ Mar 13 '18 at 13:28
  • @Hamstersztyk I think, you have misunderstood my question. – Dev b Mar 13 '18 at 13:29
  • so you should describe your problem more clearly, because now it seems duplicate – godot Mar 13 '18 at 13:30
  • @Pragnesh Ghoda, i do not want any changes in listview, i just want to add or remove custom view in activity when user clicks on listview item that it. – Dev b Mar 13 '18 at 13:32
  • Where to add in Activity and where is your ListView You should explain that clearly. – Kunu Mar 13 '18 at 13:35
  • What i get you want something like `ChipView` to add/remove tags on list Item click . Right now its too broad cause you did not provide any effort of code . So google it `ChipView` . If this is your problem . – ADM Mar 13 '18 at 13:36

1 Answers1

0

I do not know what UI effect do you want.
1. If you want the top panel section in your image fixed(do not scroll) when scroll list, then you can:

  • Use a LinearLayout as root element
  • Add a LinearLayout as top panel
  • Add ListView below top panel
  • Create a selectedView.xml that you what add to top panel when click a item of ListView

When user clicks item of ListView, you can try code below:

ItemModel itemData = dataList.get(position)
// inflate selectItemView and add to top panel
View selectItemView= LayoutInflater.from(this).inflate(R.layout.selectedView, topPanelView, true);
View text1 = selectItemView.findViewById(xxx);
text1.setText(itemData.getxxx);
...
//inflate other field using itemData
...
  1. If you want top panel scroll out of top when scroll ListView.
    Make top panel as HeaderView of ListView and follow the part step of 1 and code.
leimenghao
  • 226
  • 1
  • 10