相关疑难解决方法(0)

将onclicklistener添加到listview(android)

我已经设法实现了一个很棒的列表视图,我在这里找到了http://www.learn-android.com/2011/11/22/lots-of-lists-custom-adapter/comment-page-1/ 但我可以似乎添加了一个onclicklistener我只是希望能够在我点击该行时执行操作,该行包含的数据当然有任何想法吗?谢谢

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.liste);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Setup the list view
    final ListView prestListView = (ListView) findViewById(R.id.list);
    final prestationAdapterEco prestationAdapterEco = new prestationAdapterEco(this, R.layout.prestation);

    prestListView.setAdapter(prestationAdapterEco);

    // Populate the list, through the adapter
    for(final prestationEco entry : getPrestations()) {
        prestationAdapterEco.add(entry);
    }
    prestListView.setClickable(true);
    prestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            Object o = prestListView.getItemAtPosition(position);
            String str=(String)o;//As you are using Default String Adapter
            Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT).show();
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

android listview onclicklistener

27
推荐指数
2
解决办法
11万
查看次数

标签 统计

android ×1

listview ×1

onclicklistener ×1