How to change the layout of only the selected listview row using onitemclicklistener listview

I need to create a ListView as a Samsung Contact List . And I need to show a custom layout for this line, while this line is swiped . It is also necessary to show contact information against the background of this line. Please give me some ideas or recommendations.

Thanks.

 list.setOnItemClickListener(stationSelectionListener); final ListSwipeDetector listSwipeDetector=new ListSwipeDetector(); list.setOnTouchListener(listSwipeDetector); new UserAndMessageCount(StationListActivity.this).execute(); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (listSwipeDetector.swipeDetected()){ Toast.makeText(StationListActivity.this,"sWIPE1",Toast.LENGTH_LONG).show(); LayoutInflater inflater=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View viewNew=inflater.inflate(R.layout.view_flow_common_page, null); view=viewNew; } else { ConstantValues.STATION_NAME=((TextView)view.findViewById(R.id.textView)).getText().toString(); LayoutInflater inflater=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View viewNew=inflater.inflate(R.layout.view_flow_common_page, null); //startActivity(new Intent(getApplicationContext(), StationSelectionActivity.class)); } } }); list.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view,int position, long id) { if (listSwipeDetector.swipeDetected()){ Toast.makeText(StationListActivity.this,"sWIPE3",Toast.LENGTH_LONG).show(); } else { Toast.makeText(StationListActivity.this,"sWIPE4",Toast.LENGTH_LONG).show(); } return false; } }); 
+2
source share
1 answer

Inside onItemClickListener you can implement onItemClick (AdapterView<?> parent, View view, int position, long id) . If you retrieve the view , you can make the necessary changes for it when the user clicks on this element.

For scrolling, you can change the adapter function getItem() and add a GestureListener or something like this code . Then you can listen to the soundtracks and act accordingly.

+2
source

Source: https://habr.com/ru/post/1200521/


All Articles