点击一个ListView列表项不响应 [英] Click on list item of a ListView doesn't respond

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

问题描述

喜。通过我下面的列表视图项所列code不响应点击任何关系。可能有人帮助我吗?在此先感谢。

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天全站免登陆