Java ListView项目未响应点击

Java ListView项目未响应点击,java,android,listview,android-tabhost,Java,Android,Listview,Android Tabhost,我刚开始使用Android,并构建了一个包含三个选项卡的TabHost的UI。每个选项卡都由其自己的活动提供动力。第一个选项卡包含一个具有预填充行集的listview,它是从自定义ArrayAdapter构建的 我遇到的问题是没有一个ListView行是可点击的。换句话说,当我点击它们时,没有橙色的选择。如果我在NexusOne上使用滚动球,它会选择,但任何触摸手势似乎都没有响应 所有UI都使用XML文件处理,其中main.XML包含TabHost->LinearLayout->TabWidge

我刚开始使用Android,并构建了一个包含三个选项卡的TabHost的UI。每个选项卡都由其自己的活动提供动力。第一个选项卡包含一个具有预填充行集的listview,它是从自定义ArrayAdapter构建的

我遇到的问题是没有一个ListView行是可点击的。换句话说,当我点击它们时,没有橙色的选择。如果我在NexusOne上使用滚动球,它会选择,但任何触摸手势似乎都没有响应

所有UI都使用XML文件处理,其中main.XML包含TabHost->LinearLayout->TabWidget/FrameLayout,附近的_activity.XML文件包含我的ListView UI

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"  
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView  
    android:id="@+id/android:empty" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:text="@string/nearby_no_events" 
  />  

  <ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1.0"
    android:choiceMode="multipleChoice"
    android:divider="#d9d9d9"
    android:dividerHeight="1px"    
    android:cacheColorHint="#eee"  
  />  
</LinearLayout>

以及“我的活动”中设置为显示在所选选项卡中的相关代码

public class NearbyActivity extends ListActivity
{
    private ArrayList<Event> m_events = null;
    private EventAdapter m_adapter = null;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nearby_activity);

            getEvents();
        this.m_adapter = new EventAdapter(this, R.layout.eventrow, m_events);
        setListAdapter(this.m_adapter);
    }

    private void getEvents() 
    {
        m_events = new ArrayList<Event>();

        for (int i = 0; i < 100 ; i++)
        {
            Event e = new Event();
            e.setEventName("Event " + i);
            e.setVenueName("Staples Center");
            e.setStartDate(new Date());
            m_events.add(e);
        }
    }

    private class EventAdapter extends ArrayAdapter<Event>
    {
        private ArrayList<Event> items;

    public EventAdapter(Context context, int textViewResourceId, ArrayList<Event> items) 
    {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView (int position, View convertView, ViewGroup parent)
    {
      View v = convertView;
      if (v == null) 
      {
          LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = vi.inflate(R.layout.eventrow, null);
      }


      Event e = items.get(position);        
      if (e != null) 
      {
        TextView nameText = (TextView)v.findViewById(R.id.eventName);
        TextView venueNameText = (TextView)v.findViewById(R.id.venueName);
        if (nameText != null) 
        {
            nameText.setText(e.getEventName());                            
        }

        if(venueNameText != null)
        {
            venueNameText.setText(e.getVenueName());
        }
      }

      return v;
    }
    }
}
公共类NearbyActivity扩展了ListActivity
{
private ArrayList m_events=null;
私有事件适配器m_adapter=null;
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.Nearned_活动);
getEvents();
this.m_adapter=新事件适配器(this,R.layout.eventrow,m_事件);
setListAdapter(此.m_适配器);
}
私有void getEvents()
{
m_events=new ArrayList();
对于(int i=0;i<100;i++)
{
事件e=新事件();
e、 setEventName(“事件”+i);
e、 setVenueName(“斯台普斯中心”);
e、 设置开始日期(新日期());
m_事件。添加(e);
}
}
私有类EventAdapter扩展了ArrayAdapter
{
私有ArrayList项;
公共事件适配器(上下文上下文、int textViewResourceId、ArrayList项)
{
super(上下文、textViewResourceId、项);
这个项目=项目;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图)
{
视图v=转换视图;
如果(v==null)
{
LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
v=vi.充气(R.layout.eventrow,空);
}
事件e=项目。获取(位置);
如果(e!=null)
{
TextView name text=(TextView)v.findviewbyd(R.id.eventName);
TextView-venueNameText=(TextView)v.findViewById(R.id.venueName);
如果(nameText!=null)
{
setText(例如getEventName());
}
如果(VenuNameText!=null)
{
setText(例如getVenuName());
}
}
返回v;
}
}
}
我的listview行也由XML文件填充

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="?android:attr/listPreferredItemHeight"
  android:orientation="vertical"
  android:padding="4dip">

  <TextView
    android:id="@+id/eventName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:inputType="text"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:textSize="18sp"
    android:textColor="#000"
   />

  <TextView
    android:id="@+id/venueName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/eventName"    
    android:layout_alignParentBottom="true"
    android:layout_marginRight="55dip"    
    android:singleLine="true"
    android:ellipsize="end"
    android:scrollHorizontally="true"
    android:textSize="13sp"
    android:textColor="#313131"
    android:layout_alignWithParentIfMissing="true"
    android:gravity="center_vertical"
   />      

</RelativeLayout>


感谢您提供的帮助。

如果您想要一个可点击的Listview,那么您需要实现onListItemClick()方法

为了确保橙色,您必须设置属性

android:focusable="false"

在Listview Row.xml中,如果希望Listview是可访问的,那么需要实现onListItemClick()方法

为了确保橙色,您必须设置属性

android:focusable="false"
在Listview Row.xml中