本文介绍了列表视图onitemclick监听器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Android应用程序,我需要创建 onItemClick 方法工作,但我不能这样做。下面是code其中的 onItemClick 方法不起作用。有没有人有想法,为什么它不工作?

I am working in an Android app where I need to create onItemClick method,but I fail to do so. Below is the code where the onItemClick method does not work. Does anyone have idea why it does not work?

public class sample extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.live_chat_screen);

        mListview = (ListView) findViewById(R.id.mLiveview);
        mListview.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapters, View childView,int position, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(sample.this,"Item number : " + position + " clicked",Toast.LENGTH_LONG).show();
            }
        });

下面是XML:

<ListView
     android:id="@+id/mLiveview"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"    
     android:fastScrollEnabled="true"           

     android:scrollbars="vertical" >
</ListView>

其实我已经第一次使用两种观点在我的应用程序是当应用程序打开,另一种观点认为是开放的,而列表视图越来越负载。

Actually I have used two views in my app first is when the app is open and the another view is open while the listview is getting load.

有人能帮助我。

推荐答案

您没有在您的活动设置布局。首先使用设置你的XML 的setContentView()是这样的:

You are not setting your layout in your activity. First set your xml using setContentView() like this:

setContentView(R.layout.your_xml);

然后继续

mListview = (ListView) findViewById(R.id.mLiveview);

这篇关于列表视图onitemclick监听器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:39