2011-10-21 3 views
0

내베이스 어댑터 클래스에 변수를 설정 했으므로 관련 액티비티에서이 변수를 얻고 싶습니다. 나는 이것을하는 방법을 얻지 못하고있다.베이스 어댑터에서 변수 값을 액티비티로 전달

여기 내 코드입니다.

public class TourDescAdapter extends BaseAdapter { 

    private List<Descriptions> descriptList; 
    private LayoutInflater mInflater; 
    ViewHolder holder; 
    @SuppressWarnings("unused") 
    private OnClickListener clickListener; 
    Activity context; 
    //TourDescription tourDesc; 
    ArrayList<HashMap<String, Object>> obj = new ArrayList<HashMap<String, Object>>(); 
    HashMap<String, Object> discountedTourDetails = null; 
    String price = null, prodId = null; 
    String promoTourname, tourName; 

    public TourDescAdapter(List<Descriptions> descriptList, 
      TourDescription activity) { 
     this.context = activity; 
     this.descriptList = descriptList; 
     mInflater = LayoutInflater.from(activity); 
     clickListener = (OnClickListener) activity; 

    } 

    @Override 
    public int getCount() { 

     return this.descriptList.size(); 
    } 

    @Override 
    public Object getItem(int position) { 

     return this.descriptList.get(position); 

    } 

    @Override 
    public long getItemId(int position) { 

     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.tourlist, null); 

      /**** 
      * Creates a ViewHolder and store references to the two children 
      * views we want to bind data to 
      ****/ 
      holder = new ViewHolder(); 
      holder.rlayout = (RelativeLayout) convertView 
        .findViewById(R.id.tourlayout); 

      holder.title = (TextView) convertView 
        .findViewById(R.id.tourtitletext); 
      holder.desc = (TextView) convertView.findViewById(R.id.tourdes); 
      holder.amountButton = (Button) convertView 
        .findViewById(R.id.amtBtn); 
      holder.pinButton = (Button) convertView.findViewById(R.id.pinBtn); 
      holder.arrowButton = (Button)convertView.findViewById(R.id.arrowBtn); 
      holder.serialText = (EditText)convertView.findViewById(R.id.pinText); 
      convertView.setTag(holder); 

     } else { 

      holder = (ViewHolder) convertView.getTag(); 
     } 

     holder.title.setText((String) descriptList.get(position) 
       .getImageTitle()); 
     holder.desc.setText((String) descriptList.get(position) 
       .getImageDescription()); 
     ((ImageView) holder.rlayout.getChildAt(0)).setImageBitmap(BitmapFactory 
       .decodeFile((RaconTours.PATH + RaconTours.city + File.separator 
         + TourDescription.currentTour.getObjtourName() 
         + File.separator + descriptList.get(position) 
         .getImagePath().split("/")[2]).replace(" ", "_"))); 

     if (position == 0) { 
      SharedPreferences settings = context.getSharedPreferences("downloadDetails", 0); 
      String isTourDownloaded = settings.getString(TourDescription.currentTour.getObjtourName(), ""); 
      if (isTourDownloaded.equals("true")) { 
      //if (!(TourDescription.downloadFile.exists())||TourDescription.downloadFile.exists() == false) { 
      //if (TourDescription.currentTour.getIsTourDownloaded() == true) { 
       //holder.pinButton.setVisibility(View.INVISIBLE); 
       //holder.arrowButton.setVisibility(View.INVISIBLE); 
       //holder.serialText.setVisibility(View.INVISIBLE); 
       } 
       holder.amountButton.setVisibility(View.VISIBLE); 
       holder.amountButton.setText("Start"); 



      } else { 
       File promoPlistPath = new File(RaconTours.PATH + "promocode.txt"); 
       checkPromoCode(promoPlistPath); 
       if (discountedTourDetails != null) { 
        tourName = (String) discountedTourDetails.get("promoTour"); 
        price = (String) discountedTourDetails.get("discountPrice"); 
        prodId = (String) discountedTourDetails.get("disProId"); 

        holder.amountButton.setVisibility(View.VISIBLE); 
        // Setting the background color 
        holder.title 
          .setBackgroundColor(Color.parseColor("#993333")); 
        // Setting the Title color 
        holder.title.setTextColor(Color.WHITE); 
        // Centering the title 
        holder.title.setGravity(Gravity.LEFT); 
        // setting the city 
        ((TextView) holder.rlayout.getChildAt(1)) 
          .setText(RaconTours.city); 
        ((TextView) holder.rlayout.getChildAt(1)) 
          .setVisibility(View.VISIBLE); 
        // setting the Tour Amount 
        holder.amountButton.setText("$" +price); 
        //promoPlistPath.delete(); 
       } else { 

        // Enabling the two buttons 
        holder.amountButton.setVisibility(View.VISIBLE); 
        // Setting the background color 
        holder.title 
          .setBackgroundColor(Color.parseColor("#993333")); 
        // Setting the Title color 
        holder.title.setTextColor(Color.WHITE); 
        // Centering the title 
        holder.title.setGravity(Gravity.LEFT); 
        // setting the city 
        ((TextView) holder.rlayout.getChildAt(1)) 
          .setText(RaconTours.city); 
        ((TextView) holder.rlayout.getChildAt(1)) 
          .setVisibility(View.VISIBLE); 
        // setting the Tour Amount 
        holder.amountButton.setText(TourDescription.currentTour 
          .getObjPrice()); 

       } 
      } 
     } else { 
      holder.amountButton.setVisibility(View.INVISIBLE); 
      holder.pinButton.setVisibility(View.INVISIBLE); 
      holder.arrowButton.setVisibility(View.INVISIBLE); 
      holder.serialText.setVisibility(View.INVISIBLE); 
      holder.title.setBackgroundColor(Color.WHITE); 
      holder.title.setTextColor(Color.BLACK); 
      holder.title.setGravity(Gravity.CENTER_HORIZONTAL); 
      ((TextView) holder.rlayout.getChildAt(1)) 
        .setVisibility(View.INVISIBLE); 
     } 
     return convertView; 
    } 


    @SuppressWarnings("unchecked") 
    private void checkPromoCode(File promoPlistPath) { 
     if (promoPlistPath.exists()) { 
      try { 

       ObjectInputStream inStream = new ObjectInputStream(
         new FileInputStream(promoPlistPath)); 
       obj = (ArrayList<HashMap<String, Object>>) inStream 
         .readObject(); 
       for (HashMap<String, Object> tmpObj : obj) { 
        promoTourname = (String) tmpObj.get("promoTour"); 
        if (promoTourname.equals(TourDescription.currentTour.getObjtourName())) { 
         discountedTourDetails = tmpObj; 
         break; 
        } 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    class ViewHolder { 
     Button pinButton; 
     Button amountButton; 
     RelativeLayout rlayout; 
     TextView title; 
     TextView desc; 
     Button arrowButton; 
     EditText serialText; 

    } 
} 

여기

prodId = (String) discountedTourDetails.get("disProId"); 

나는 관련 활동에 PRODID를 전달하려는.

참고 : 기본 어댑터가 활동

adapter = new TourDescAdapter(currentTour.getListOfDescriptions(), this); 

    setListAdapter(adapter); 

어떻게 이렇게 말해 줄 수있는 모든 하나라고?

+0

반환 변수 값을 사용하여 어댑터에 공용 메서드를 만들고 variable = adapter.methodName(); –

+0

@tejas 나는 같은 문제가있어! 어떻게 baseadapter에서 값을 –

+0

님께 전할 수 있을까요? 안녕하세요 priya, 지연된 응답에 대해 사과드립니다. 요즘 인터넷에 접속할 수 없었습니다. 시나리오가 정확히 무엇인지 말해 줄 수 있습니까? – tejas

답변

3

String iGotTheString = adapter.prodId을 사용할 수 없습니까?

+0

나는 문제를 해결했다. 표준 방법이 아닐지 모르지만 나의 의도는 이것을 고치는 것이었다. 나는 이것을 생성자 checkPromoCode (promoPlistPath) 내부에서 호출한다. \t \t 경우 (discountedTourDetails = 널!) { \t \t \t PRODID = (문자열) discountedTourDetails.get ("disProId"); \t \t} – tejas

+0

표준 방법을 말해 줄 수 있다면 가장 환영합니다. – tejas