Set long click listener for listview

后端 未结 5 526
心在旅途
心在旅途 2021-01-17 17:31

I have below codes:

public class MainActivity extends ListActivity { 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceSt         


        
5条回答
  •  花落未央
    2021-01-17 18:10

    yes it is possible and quite easy to achieve, simply you have to make the instance of the listview like

    ListView lv = (ListView)findViewById(R.id.listview);
    lv.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View 
                        // your code here
                        return true;
                    }
    
            });)
    

    in your case instead of extending ListActivity you can make a list view in xml and find the view in MainActivity and follow the above step.

提交回复
热议问题