有人可以解释这段代码的作用吗?

时间:2016-09-16 10:52:45

标签: android

lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position,long id) {
       try {
           text.delete(position, position);
           String item = strArr.get(position);
           strArr.remove(item);
           adapter = new ArrayAdapter<String (getApplicationContext(), android.R.layout.simple_list_item_1, strArr);
           lv.setAdapter(adapter);
           return true;
       } catch (Exception e) {
          e.getMessage();
       }
       return true;
   }  
});

1 个答案:

答案 0 :(得分:0)

以下是您在点击监听器中的详细信息:

  lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position,long id) {
           try {
               text.delete(position, position); //  removes the characters in a substring of this StringBuffer ref: http://www.tutorialspoint.com/java/stringbuffer_delete.htm
               String item = strArr.get(position); // get specified item from arraylist of string 
               strArr.remove(item); // remove the clicked item from arraylist strArr
               adapter = new ArrayAdapter<String (getApplicationContext(), android.R.layout.simple_list_item_1, strArr); // re-initialize the adapter with updated list
               lv.setAdapter(adapter); // set the adapter in your listview
               return true;
           } catch (Exception e) {
              e.getMessage();
           }
           return true;
       }  
    });