2010-05-28 1 views
1

Android가 젖어서 세 개의 탭이있는 TabHost가 포함 된 UI가 작성되었습니다. 각 탭은 자체 Activity에 의해 구동됩니다. 첫 번째 탭에는 미리 채워진 일련의 행이있는 목록 뷰가 들어 있으며 사용자 정의 ArrayAdapter에서 작성됩니다.목록보기 항목이 탭에 응답하지 않습니다.

내가 겪고있는 문제는 ListView 행 중 어느 것도 탭핑 할 수 없다는 것입니다. 즉, 내가 탭할 때 오렌지 선택이 없습니다. Nexus One에서 스크롤 볼을 사용하면 선택되지만 터치 동작이 응답하지 않는 것 같습니다.

모든 UI는 TabHost main.xml에 하우징으로 XML 파일을 사용하여 처리되고 ->의 LinearLayout -> TabWidget/FrameLayout이와 nearby_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; 
    } 
    } 
} 

내 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> 

도움을 주셔서 감사합니다.

답변

5

당신은

@Override 
    protected void onListItemClick(ListView l, View v, final int position, long id) { 
    super.onListItemClick(l, v, position, id);     
Toast.makeText(this, "This is my row number " + position,Toast.LENGTH_LONG).show(); 
    } 

당신이 당신의 목록보기 Row.xml에서 속성

android:focusable="false" 

를 설정해야합니다 오렌지 색상을 보장하기 위해) (onListItemClick 아니라 당신이 메소드를 구현해야 목록보기가 tappable합니다

+0

그게 전부입니다. 감사. –