список адаптеров для фрагментов - PullRequest
0 голосов
/ 06 марта 2012

Я использую фрагменты в своем приложении. Это для функции вкладок. На вкладке мне нужно отобразить список в viewflipper. Представление списка представляет собой отдельный файл XML. У меня есть представление списка с представлением flipper.the содержимого (элементы списка) представления списка - это еще один xml-файл. Он содержит четыре textview. Значения textview устанавливаются динамически. Я создал для этого специальный адаптер с именем store store. Но проблема в том, что я не могу использовать этот адаптер store в моей программе. Когда я использую это, он не отображает значения. Так как элементы представления списка - это отдельный файл, я не могу также расширить listfragment. Я не знаю, что я должен сделать, чтобы отобразить мой контент. Ниже приведен мой код .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 Ответ

1 голос
/ 09 марта 2012

Будет работать нестандартный адаптер списка.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...