2012-03-06 128 views
0

我在我的應用程序中使用片段。它是用於製表符功能。在一個標籤中,我需要在viewflipper中顯示一個列表。列表視圖是一個單獨的xml文件。我用視圖擴充了列表視圖flipper.list視圖的內容(列表項)是另一個xml文件,它包含四個文本視圖。文本視圖的值是動態設置的。我爲此創建了一個名爲store adapter的自定義適配器。但問題是我不能在我的程序中使用這個存儲適配器。當我使用它時,它不顯示值。因爲列表視圖項目是一個單獨的文件,我無法擴展listfragment以及。我不知道我應該怎麼做來顯示我的內容..given下面是我的code.plz幫助我。片段的適配器

public class TabStoreLocatorFragment extends Fragment implements OnClickListener { 

private Button mapSwitcher; 
private LinearLayout lastSelectedStoreButton; 
private LinearLayout noSelectedStoreSection; 
private TextView storeInfoName; 
private TextView storeInfoAddress; 
private TextView storeInfoCity; 
private RelativeLayout phoneLocationButton; 
private EditText searchStoreLocation; 
private ListView storeList; 
private ViewFlipper storeFlipper; 
private LinearLayout theLayout; 
private Store store; 
private Context context; 
private String searchStoreText; 

//private ProgressDialog findStoreProgressDialog; 
//private StoreItemizedOverlay<StoreOverlayItem> storeOverlay; 
//private List<Overlay> mapOverlays; 
//private Drawable storePin; 

@SuppressWarnings("static-access") 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    if (container == null) { 
     // We have different layouts, and in one of them this 
     // fragment's containing frame doesn't exist. The fragment 
     // may still be created from its saved state, but there is 
     // no reason to try to create its view hierarchy because it 
     // won't be displayed. Note this is not needed -- we could 
     // just run the code below, where we would create and return 
     // the view hierarchy; it would just never be used. 
     return null; 
    } 


    context=getActivity().getApplicationContext(); 
    theLayout = (LinearLayout) inflater.inflate(
      R.layout.tab_store_locator_layout, container, false); 

    phoneLocationButton = (RelativeLayout) theLayout.findViewById(R.id.phone_location_button); 
    mapSwitcher=(Button)theLayout.findViewById(R.id.switch_state_button); 
    lastSelectedStoreButton=(LinearLayout)theLayout.findViewById(R.id.last_selected_store_button); 
    noSelectedStoreSection=(LinearLayout)theLayout.findViewById(R.id.no_selected_store); 
    storeInfoName=(TextView)theLayout.findViewById(R.id.store_name); 
    storeInfoAddress=(TextView)theLayout.findViewById(R.id.store_address); 
    storeInfoCity=(TextView)theLayout.findViewById(R.id.store_city); 
    searchStoreLocation=(EditText)theLayout.findViewById(R.id.search_store); 
    storeFlipper = (ViewFlipper)theLayout.findViewById(R.id.store_flipper); 
    storeList = (ListView)inflater.inflate(R.layout.store_list, null); 
    storeFlipper.addView(storeList); 

    store=new Store(); 
    store.setName("store1"); 
    store.setAddress("california"); 
    store.setCity("newyork"); 
    store.setZipCode("23"); 
    store.setState("california"); 

    phoneLocationButton.setOnClickListener(this); 
    mapSwitcher.setOnClickListener(this); 
    lastSelectedStoreButton.setOnClickListener(this); 
    return theLayout; 

} 


@Override 
public void onClick(View view) { 
    int id = view.getId(); 
    if (id == R.id.phone_location_button) { 

     searchStoreText=searchStoreLocation.getText().toString(); 


     @SuppressWarnings("unchecked") 
     StoreAdapter adapter = new StoreAdapter(context, R.layout.store_list_item); 

     storeList.setAdapter(adapter); 



    } 
    else if(id == R.id.switch_state_button){ 

    } 
    else{ 


    } 


} 

    } 

回答

1

自定義列表適配器將工作。