单击 ListView 的列表项没有响应 [英] Click on list item of a ListView doesn't respond

查看:18
本文介绍了单击 ListView 的列表项没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的代码中实现 ListView.但是当我点击这些项目时,它不会以任何方式响应点击.有人可以帮我吗?提前致谢.

I am implementing ListView in my code. But When I click on the items, it does not respond respond to the click in any way. Could someone help me please? Thanks in advance .

这里是代码.

public class ListaActivity extends Activity {

    public final static String EXTRA_MESSAGE = "com.example.provacomunicazione.MESSAGE";
    @Override
    public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.lsta);
        Resources res = getResources();
        String[] Authors = res.getStringArray(R.array.Lista_Nomi_E_Cognomi_Autori);
        ArrayList<String> Autori = new ArrayList<String>();
        for (String temp:Authors) {
            Autori.add(temp);
        }
        Collections.sort(Autori);
        ArrayList<String> AutoriLetteraSelezionata = new ArrayList<String>();
        for (String temp:Autori) {
            if (temp.charAt(0)=='A') {
                AutoriLetteraSelezionata.add(temp);
            }
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.textviewitem, AutoriLetteraSelezionata);
        ListView listView = (ListView) findViewById(R.id.listView1);
        listView.setAdapter(adapter);
        listView.setClickable(true);
        listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

            CharSequence autore = "("+((TextView)view).getText()+")";

            Intent i = new Intent(ListaActivity.this, SecondaryActivity.class);
            i.putExtra(EXTRA_MESSAGE, autore);
            startActivity(i);  
        });
    }
}    

推荐答案

您应该在项目列表视图(TextView、ImageView 等)中定义所有子对象:

You should define on all of the child objects in the item listview (TextView, ImageView etc.):

android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"

对于根项RelativeLayout/LinearLayout等,定义:

And for the root item RelativeLayout / LinearLayout and so, define:

android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"

如果您不定义这些,它们将捕获"点击事件.如果您有自定义 listView 适配器,只需检查您是否覆盖:

If you won't define those, they will "catch" the click event. And if you have a Custom listView adapter, just check that you override:

@Override
public boolean isEnabled(int position)
{
    return true;
}

这篇关于单击 ListView 的列表项没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆