2013-03-01 7 views
5

मैं अपने प्रोजेक्ट में उपयोग के लिए एक जार के रूप में फेसबुक एंड्रॉइड एसडीके निर्यात करने की कोशिश कर रहा हूं।R.styleable संसाधन को गतिशील रूप से लोड करने के लिए कैसे करें?

इसके लिए सभी संसाधनों को गतिशील रूप से लोड करने की आवश्यकता है।

उदाहरण के लिए, मैं परिवर्तन इस के समान बनाने के लिए है:

//findViewById(R.id.com_facebook_login_activity_progress_bar).setVisibility(View.VISIBLE); 
int viewID = getResources().getIdentifier("com_facebook_login_activity_progress_bar", "id", getPackageName()); 
findViewById(viewID).setVisibility(View.VISIBLE); 

टिप्पणी की लाइन मूल पता चलता है, और 2 लाइनों के नीचे प्रदर्शित परिवर्तन मैं गतिशील समान संसाधन लोड करने के लिए बनाया है।

फेसबुक एसडीके एक आरस्टाइल योग्य संसाधन घोषित करता है, और मैं इसे गतिशील रूप से लोड करने का तरीका नहीं समझ सकता।

private void parseAttributes(AttributeSet attrs) { 
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view); 
    setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM)); 
    isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE); 
    a.recycle(); 
} 

फिर attrs.xml में, निम्न घोषित किया जाता है:: यहाँ मूल कोड है

<declare-styleable name="com_facebook_profile_picture_view"> 
     <attr name="preset_size"> 
      <!-- Keep in sync with constants in ProfilePictureView --> 
      <enum name="small" value="-2" /> 
      <enum name="normal" value="-3" /> 
      <enum name="large" value="-4" /> 
     </attr> 
     <attr name="is_cropped" format="boolean" /> 
    </declare-styleable> 

मैं कैसे (जैसे R.styleable संदर्भ की जगह) गतिशील रूप से इस संसाधन लोड कर सकते हैं?

+1

http://stackoverflow.com/questions/13816596/accessing-:

मैं समारोह इस सवाल का जवाब में वर्णित इस्तेमाल किया घोषणा-शैली-संसाधन-प्रोग्रामेटिक रूप से) पोस्ट वर्तमान समस्या को हल करने में आपकी मदद कर सकता है –

+0

बहुत बढ़िया, त्वरित प्रतिक्रिया के लिए धन्यवाद .. यही वही था जो मुझे चाहिए था। यदि आप उत्तर के रूप में पोस्ट करते हैं तो मैं इसे चेकमार्क कर दूंगा! – ch3rryc0ke

उत्तर

3

मैं यहां सवाल का जवाब दे रहा हूं कि कोई भी विशेष रूप से फेसबुक एसडीके को जार के रूप में निर्यात करने की कोशिश कर रहा है। देखें [एक्सेस करना <घोषित-Styleable> संसाधन प्रोग्राम के] ( Accessing <declare-styleable> resources programatically

private void parseAttributes(AttributeSet attrs) { 
    int attrArray[] = StyleableHelper.getResourceDeclareStyleableIntArray(getContext(), "com_facebook_profile_picture_view"); 
    //TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view); 
    TypedArray a = getContext().obtainStyledAttributes(attrs, attrArray); 

    setPresetSize(a.getInt(0, CUSTOM)); 
    isCropped = a.getBoolean(1, IS_CROPPED_DEFAULT_VALUE); 
    //setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM)); 
    //isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE); 
    a.recycle(); 
} 
संबंधित मुद्दे