2013-10-16 62 views
1

在我的小部件中,當listview中的某個項目被長時間按下時,我希望該項目被啓動(在我的編碼中然而,目前正常的點擊操作也是如此,但現在我正在做長時間點擊操作,以便稍後當我需要更改長點擊時進行設置)。返回類型與AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView <?>,View,int,long)兼容

這裏是我的編碼:

package com.example.awesomefilebuilderwidget; 

import android.app.Activity; 
import android.content.pm.ApplicationInfo; 
import android.os.Bundle; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemLongClickListener; 
import android.widget.EditText; 
import android.widget.ListView; 
import android.widget.AdapterView.OnItemClickListener; 

public class Drag_and_Drop_App extends Activity { 
private ListView mListAppInfo; 
// Search EditText 
EditText inputSearch; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // set layout for the main screen 
    setContentView(R.layout.drag_and_drop_app); 
    // create new adapter 
    AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this), getPackageManager()); 
    // set adapter to list view 
    mListAppInfo.setAdapter(adapter); 
    // search bar 
    inputSearch = (EditText) findViewById(R.id.inputSearch); 

    inputSearch.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { 
      // When user changed the Text 
      Drag_and_Drop_App.this.adapter.getFilter().filter(cs); 

     } 

     @Override 
     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, 
       int arg3) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable arg0) { 
      // TODO Auto-generated method stub       
     } 
     }); 
    // load list application 
    mListAppInfo = (ListView)findViewById(R.id.lvApps); 

    // implement event when an item on list view is selected 
    mListAppInfo.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView parent, View view, int pos, long id) { 
      // get the list adapter 
      AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter(); 
      // get selected item on the list 
      ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos); 
      // launch the selected application 
      Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName); 
     } 

    }); 

    // implement event when an item on list view is selected via long-click for drag and drop 
    mListAppInfo.setOnItemLongClickListener(new OnItemLongClickListener(){ 

     @Override 
     public void onItemLongClick(AdapterView parent, View view, 
       int pos, long id) { 
      // TODO Auto-generated method stub 
      // get the list adapter 
      AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter(); 
      // get selected item on the list 
      ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos); 
      // launch the selected application 
      Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName); 
     } 


    }); 
} 
} 

正如你所看到的,我基本上是設立長按做同樣的事情,作爲一個正常的點擊,但我得到的錯誤,返回類型是兼容這條線:

  public void onItemLongClick(AdapterView parent, View view, 

快速修復告訴我改變返回類型爲布爾值(這是不對的)。

我該如何解決這個問題?

回答

1

快速修復告訴我將返回類型更改爲布爾值(這是不正確的)。

爲什麼不是這樣?

According to the Docs

速戰速決是正確的。給它返回類型booleanreturn true。這讓我們知道,長點擊是成功的。

+0

哦,那時我錯了。感謝您的迴應!我將返回類型更改爲布爾值,並將其設置爲true,現在沒有錯誤。 :) – user1628978

相關問題