2014-11-10 6 views
1

나는 custom listview와 spinner를 가지고있다. 우선 listview를 채운 다음 드롭 다운 스피너를 클릭한다. 나는 item (city)을 선택한다. listview를 새로운 result로 업데이트하고 싶다. 그러나 사용자 정의 어댑터 getview는 호출하지 않습니다. 따라서 listview는 업데이트되지 않습니다. 내 화면입니다 enter image description here맞춤 회 전자가 맞춤 목록보기를 호출하지 않습니까?

어떻게해야합니까?

여기 회 충전하고

private void getCityListWithSpinner() { 

     cityListRequest = new CityListRequest(new AsyncListener() { 

      @Override 
      public void asyncOperationSucceded(Object obj, int queue) { 

       System.out.println("Objemizzz " + obj.toString()); 

       cityArrayList = (ArrayList<CityList>) obj; 
       Spinner ss = (Spinner) findViewById(R.id.cityfilmspinner); 

       CinemaCitySelector2 citySelector = new CinemaCitySelector2(); 
       cityList.add("Seçiniz"); 
       for (int i = 0; i < cityArrayList.size(); i++) { 
        cityList.add(cityArrayList.get(i).getCinemaCity()); 
        citySelector.CinemaCitySelector2(
          CinemaCityMoviePickerActivity.this, ss, cityList,2); 

       } 

      } 

CinemaCitySelector :

public class CinemaCitySelector2 implements OnItemSelectedListener { 

    Context context2; 
    Spinner spinner2; 
    CityListInCityRequest cityListInCityRequest2; 
    ArrayList<Cinema> cityListInCityArrayList2; 
    ListView list_cinema_movie_selectorr2; 
    CinemaListViewAdapter2 adapter2; 
    View row2; 
    int act2 = 0; 

    Spinner cityspinner; 

    public void CinemaCitySelector2(Context context, Spinner spinner, 
      ArrayList<String> cityList, int activityfrom) { 

     this.context2 = context; 
     this.spinner2 = spinner; 
     act2 = activityfrom; 

     // Declaring an Adapter and initializing it to the data pump 
     ArrayAdapter adapter = new ArrayAdapter(context, 
       android.R.layout.simple_list_item_1, cityList); 

     // Setting Adapter to the Spinner 
     spinner.setAdapter(adapter); 

     // Setting OnItemClickListener to the Spinner 
     spinner.setOnItemSelectedListener(CinemaCitySelector2.this); 

    } 

    // Defining the Callback methods here 
    public void onItemSelected(AdapterView parent, View view, int pos, long id) { 

     String city = spinner2.getItemAtPosition(pos).toString(); 


      LayoutInflater layoutInflater = LayoutInflater.from(context2); 
      row2 = layoutInflater.inflate(
        R.layout.activity_cinemacitymoviepicker, null, false); 
      list_cinema_movie_selectorr2 = (ListView) row2 
      .findViewById(R.id.listfilmincinema); 


     if (!city.equals("Seçiniz")) { 

      cityListInCityRequest2 = new CityListInCityRequest(
        new AsyncListener() { 

         @Override 
         public void asyncOperationSucceded(Object obj, int queue) { 

          // adapter.clear(); 
          // adapter.notifyDataSetChanged(); 
          // list_cinema_movie_selector.setAdapter(adapter); 
          System.out.println("Objemizzz " + obj.toString()); 

          cityListInCityArrayList2 = (ArrayList<Cinema>) obj; 
          // adapter.notifyDataSetChanged(); 
          adapter2 = new CinemaListViewAdapter2(context2, 
            R.layout.cinema_list, 
            cityListInCityArrayList2); 

           list_cinema_movie_selectorr2 
             .setAdapter(adapter2); 



         } 

         @Override 
         public void asyncOperationFailed(Object obj, int queue) { 
          // TODO Auto-generated method stub 
          System.out.println("Objemizzz2 " + obj.toString()); 

         } 
        }, city); 
     } 
    } 

    public void onNothingSelected(AdapterView arg0) { 
     // TODO Auto-generated method stub 

    } 

} 

CinemaListViewAdapter2 :

public class CinemaListViewAdapter2 extends ArrayAdapter<Cinema> { 

    Context context; 
    int arraycount=0; 



    public CinemaListViewAdapter2(Context context, int resourceId, 
      ArrayList<Cinema> items) { 
     super(context, resourceId, items); 
     this.context = context; 
     arraycount=items.size(); 
    } 

    /*private view holder class*/ 
    private class ViewHolder { 
     BlackBrandTextview cinemaName; 
     RelativeLayout cinemalist; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder = null; 
     Cinema rowItem = getItem(position); 


     LayoutInflater mInflater = (LayoutInflater) context 
       .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.cinema_list, null); 
      holder = new ViewHolder(); 
      holder.cinemaName = (BlackBrandTextview) convertView.findViewById(R.id.txt_cinema_name); 
      holder.cinemalist=(RelativeLayout)convertView.findViewById(R.id.cinemalist); 
      holder.cinemaName.setText(rowItem.getCinemaName()); 
      if(rowItem.getCinemaDistance()<5000){ 

       holder.cinemalist.setBackgroundColor(context.getResources().getColor(R.color.Cinema_Pink)); 
       holder.cinemaName.setTextColor(context.getResources().getColor(R.color.Cinema_Black)); 

      } 
      else{ 
       holder.cinemalist.setBackgroundColor(context.getResources().getColor(R.color.Cinema_Black)); 
       holder.cinemaName.setTextColor(context.getResources().getColor(R.color.White)); 

      } 

      convertView.setTag(holder); 
     } else{ 
      holder = (ViewHolder) convertView.getTag(); 

      holder.cinemaName.setText(rowItem.getCinemaName()); 


     } 

     if(rowItem.getCinemaDistance()<5000){ 

      holder.cinemalist.setBackgroundColor(context.getResources().getColor(R.color.Cinema_Pink)); 
      holder.cinemaName.setTextColor(context.getResources().getColor(R.color.Cinema_Black)); 

     } 
     else{ 
      holder.cinemalist.setBackgroundColor(context.getResources().getColor(R.color.Cinema_Black)); 
      holder.cinemaName.setTextColor(context.getResources().getColor(R.color.White)); 

     } 


     holder.cinemaName.setText(rowItem.getCinemaName()); 

     return convertView; 
    } 
+0

를? 회 전자 값에서 초기 목록을 업데이트 한 다음 초기 어댑터를 업데이트하는 것이 좋습니다 - [example] (http://stackoverflow.com/a/19833695/4123144) 참조 – Wildroid

답변

0

난 당신이 전화를하는 것이 좋습니다

adapter2.notifyDataSetChange(); 

하지만 어쨌든 새 어댑터를 매번 초기화 할 필요가 없습니다. 이 같은 어댑터 내부의 방법을 만들어야합니다

public void setMyArray(ArrayList<Cinema> items) { 
    myArray.clear(); 
    myArray.addAll(items); 
    notifyDataSetChange(); 
} 
1

내가 어댑터를 업데이트하는 방법을 만들 것입니다 귀하의 스피너의 항목이 선택되면 :

cityspinner.setOnItemSelectedListener(new OnItemSelectedListener() { 
    public void onItemSelected(AdapterView<?> parent, View view,int position, long id) { 
     city = (String) parent.getItemAtPosition(position); 
     resetCinema(city); //or onRestart(); 
} 

public void onNothingSelected(AdapterView<?> parent){ 
} 
}); 

그리고 resetCinema(city)보기를 rechages 도시 가치에 따라.

public void resetCinema(String city) { 
    //show list view elements depending on city 
} 

을하거나 전체 활동의 새로 고침 전화 : 수동으로이 작업을 수행 할 수 있습니다 onItemSelected 회 전자의 다른 레이아웃을 부풀려 왜

protected void onRestart() { 
    Intent refresh = new Intent(this, Main.class); 
    startActivity(refresh);//Start the same Activity 
    finish(); //finish Activity. 
} 
관련 문제