How to change layout of only selected listview row with in onitemclicklistener of listview
Asked Answered
W

1

2

I need to create ListView like Samsung Contact List. And I need to show custom layout for that row while that row is swiped. And also need to show contact detail at background of that row. Please give me some ideas or reference.

Thank You.

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;
        }
    });
Warner answered 7/2, 2013 at 8:2 Comment(0)
R
2

Within onItemClickListener, you can implement onItemClick (AdapterView<?> parent, View view, int position, long id). If you retrieve the view, you can make the changes you need for it when the user clicks on that item.

For swiping, you can modify your adapter's getItem() function and add a GestureListener or something like this code. Then you can listen for swipes and act accordingly.

Rehabilitate answered 7/2, 2013 at 8:10 Comment(4)
I'm sorry, I cann't able to create my view. I know upto listview swipe but don't know how to change the selected row of the listview.Warner
Where are you trying to change the selected row? Inside getItem()? Or inside onItemClick()?Rehabilitate
I don't know about getItem() so i was tried with onItemClick().Warner
The second argument, view, of onItemClick() is that item's row. You can then cast it to whatever view it is and use findViewById() to access other views in that row.Rehabilitate

© 2022 - 2024 — McMap. All rights reserved.