OnView与Listview

时间:2011-07-08 06:54:55

标签: android listview ontouchlistener

我正在使用带有listview的onTouchListener我在哪里使用motionevent Action_up, 我将如何在列表视图中创建执行Action_up事件的项目。 我的代码如下

package com.example.ListViewDemo;

    import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListViewDemo extends ListActivity {
    TextView selection;
    String[] items={"adipiscing","aliquet","amet","ante" };



    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            items));
     ListView lv = getListView();
      lv.setTextFilterEnabled(true);
/*    lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                  // When clicked, show a toast with the TextView text
                  Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                      Toast.LENGTH_SHORT).show();
                }
              });   */
      lv.setOnTouchListener(new OnTouchListener(){



          public boolean onTouch(View v, MotionEvent event){
              Log.d("Manoj", "onTouch entered");
              if(event.getAction() == MotionEvent.ACTION_UP) {
                  Log.d("Manoj", "ACTION_UP");
               //   v.setPressed(true);
                  int x = (int) event.getX();
                  int y = (int) event.getY(); 

              }
              return false;
          }
      });
            selection=(TextView)findViewById(R.id.selection);
            }
            public void onListItemClick(ListView parent, View v, int position,
            long id) {
            selection.setText(items[position]);


            }




            }

任何人都可以帮忙吗? 提前致谢

0 个答案:

没有答案