这段代码有什么问题?
我尝试向列表视图添加一个长点击监听器,但由于某种原因无法正确处理:
package ch.futurecom.adaptertest;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class AdapterTestActivity extends ListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ListView lv = getListView();
lv.setLongClickable(true);
lv.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
Toast.makeText(AdapterTestActivity.this, "long clicked", Toast.LENGTH_SHORT).show();
return true;
}
});
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row,getResources().getStringArray(R.array.items)));
}
}
pastebin 链接:
AdapterTestActivity.java -> http://pastebin.com/Pw30EkEz
row.xml -> http://pastebin.com/6FajncHT
谢谢!