2
我最近從Java移至C#和Mono以進行Android開發。我有一個ListView,我想選擇返回true或false,但在單聲道中似乎沒有這樣做的選項。下面是一些代碼片段:觸摸事件不能在單聲道中消耗
的Java(我試圖在單聲道再現)
ListView listview;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView)findViewById(R.id.listView1);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
for (int i = 0; i < 50; i++)
adapter.add(Integer.toString(i));
listview.setAdapter(adapter);
listview.setOnTouchListener(listenerOnTouch);
}
private OnTouchListener listenerOnTouch = new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
return false; // <---- This line doesn't exist in Mono
}
};
單相當於:
ListView listview;
ArrayAdapter<String> adapter;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
listview = FindViewById(Resource.Id.listView1) as ListView;
adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1);
for (int i = 0; i < 50; i++)
adapter.Add (i.ToString());
listview.Adapter = adapter;
listview.Touch += ListenerOnTouch;
}
private void ListenerOnTouch(object sender, View.TouchEventArgs e)
{
// Delegate return type is void, so I can't return true/false
}
從根本上說,我想要在此做實例是make是這樣的,如果我向上或向下拖動列表視圖,它會像平常一樣滾動,但是如果我向左或向右拖動它,則會執行其他操作。
完美地工作。非常感謝你! – 2013-03-21 11:13:50