English 中文(简体)
一览表1.6
原标题:Use both onClickListener and onLongClickListener in listview Android 1.6

我正在使用<代码>onClickListener和onLongClickListener,以备<>TextView,载于。 我看到,在安伯1.6,在我长期点击时,发射长点听众和点击听众的意思。 但今后版本的情况并非如此。 是否有这方面的规定?

@Override
public View getView(int position, View convertView, ViewGroup parent) {

  if (convertView == null) {
    LayoutInflater inflater = getLayoutInflater();
    row = inflater.inflate(R.layout.row, parent, false);
  }

  TextView tv = (TextView) row.findViewById(R.id.tv);

  tv.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        showMessage();
      }
  });

  tv.setOnLongClickListener(new View.OnLongClickListener() {
      @Override
      public boolean onLongClick(View v) {
        showLongMessage();
      }
  });
}
最佳回答

页: 1 表明你不想再加工?

问题回答

我认为,你应使用OnItemLongClickListener()而不是OnLongClickListener()。

See

TextView t1 = (TextView) findViewById(R.id.textView1);
t1.isClickable();

t1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Clicked", Toast.LENGTH_SHORT).show();
    }
});

t1.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show();
        return true;
    }
});
itemToClick.setOnClickListener(new View.OnClickListener() {
   @Override
    public void onClick(View v)      { 
      //do your logic on click 
     });
itemToClick.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
      // do your logic for long click and remember to return it 
        return true; }});




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签