2012-01-12 6 views

답변

1

예 온라인 서버의 이미지 및 텍스트와 같은 리소스를 런타임에로드 할 수 있습니다.

자신의 값을 설정 레이아웃 부풀려 응답

에서 (내가 텍스트와 이미지가 당신의 필요 조건이다, 생각) 당신의 자료를 얻을 수 귀하의 웹 서비스

을 당신이해야 할 모든이

하는 것입니다 전화 /자원.

편집 : 성능상의 이유로

는 인플레이션이 빌드시에 수행되는 XML 파일의 사전 처리에 크게 의존 봅니다 것을

제 3 단락 상태. 따라서 런타임에 평범한 XML 파일 위에 은 XmlPullParser 으로 LayoutInflater를 사용할 수 없습니다.; 컴파일 된 리소스 (R.something 파일)에서 반환 된 XmlPullParser에서만 작동합니다.

runtime에서 yourLayout.xml을 만들지는 언급하지 않았습니다.

여기 내 지점을 증명하기 위해 해당 프로젝트에서 내 클래스 중 하나의 예입니다

public class WriteScreen extends Activity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.writescreen); 
     title=(TextView)findViewById(R.id.writescreentitle); 
     array_listaudiodurationurl=new ArrayList<String>(); 
     array_listcreatorname=new ArrayList<String>(); 
     array_listtype=new ArrayList<String>(); 
     array_listurl=new ArrayList<String>(); 
     array_listcreatorid=new ArrayList<String>(); 
     array_listcreatoravatar=new ArrayList<String>(); 
     array_listid=new ArrayList<String>(); 
     array_listcontent=new ArrayList<String>(); 
     array_listduration=new ArrayList<String>(); 
     array_listtype1=new ArrayList<String>(); 
     array_listimagetype=new ArrayList<String>(); 
     array_listimageurl=new ArrayList<String>(); 
     array_listurl1=new ArrayList<String>(); 
     array_listlastmodified=new ArrayList<String>(); 
     array_listcreated=new ArrayList<String>(); 
     array_listmaintype=new ArrayList<String>(); 
     array_listsource=new ArrayList<String>(); 
     array_listaudiourl=new ArrayList<String>(); 
     Intent in =getIntent(); 

     eId = in.getStringExtra("EventsId"); 
     tit=in.getStringExtra("Title"); 
     title.setText(tit); 

     mypref = PreferenceManager.getDefaultSharedPreferences(WriteScreen.this); 
     username = mypref.getString("username", "0"); 
     password = mypref.getString("Password", "0"); 


     write=(Button)findViewById(R.id.writescreenwritebtn); 
     moderate =(Button)findViewById(R.id.writescreenmoderate); 
     users=(Button)findViewById(R.id.writescreenusers); 

     try 
     { 
      try 
      { 
      writescreen(); 

      } 
      catch (JSONException e) 
      { 

      e.printStackTrace(); 
      } 
     } 
     catch (ClientProtocolException e) 
     { 
     e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 

      e.printStackTrace(); 
     } 
     writelowerparts(); 

    } 

    public void playAudio() 
    { 
     if (WriteScreen.this.audioStreamer.getMediaPlayer().isPlaying()) 
      { 
      WriteScreen.this.audioStreamer.getMediaPlayer().pause(); 
      } 
      else 
      { 
       WriteScreen.this.audioStreamer.getMediaPlayer().start(); 
       WriteScreen.this.audioStreamer.startPlayProgressUpdater(); 
      } 
     isPlaying = !isPlaying; 
    } 

    public void writelowerparts() 
    { 
     boolean isgrey=true; 
     TableLayout tl = (TableLayout)findViewById(R.id.myTableLayoutwritescreen); 
     tl.setOrientation(LinearLayout.VERTICAL); 

      if (tl != null) 
      { 
       tl.removeAllViews(); 
      } 
     if(array_listcreatorid.size() > 0) 
     { 
      LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
      LayoutParams lpAddRow = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
      LayoutParams lpImageView = new LayoutParams(MyEvents.width - (MyEvents.width/2), LayoutParams.WRAP_CONTENT); 
      LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 

      for(i = 0; i < array_listcreatorid.size(); i++) 
      { 
      Calendar calendar = Calendar.getInstance(); 
      int ro = calendar.getTimeZone().getRawOffset(); 
      int dst = calendar.getTimeZone().getDSTSavings(); 
      int startInd = array_listlastmodified .get(i).indexOf("("); 

      int EndInd = array_listlastmodified.get(i).indexOf("+") ; 
      String createdDate = array_listlastmodified.get(i).substring(startInd + 1, EndInd); 
      long created1 = Long.parseLong(createdDate) + ro + dst; 
      Date cDate = null; 
      SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss "); 
      formatter.setTimeZone(TimeZone.getTimeZone("UTC"));//TimeZone.getDefault()); 
      String dateString = formatter.format(new Date(created1)); 
      calendar.setTimeInMillis(created1); 
      calendar.setTimeZone(TimeZone.getDefault()); 
      TableRow tr = new TableRow(this); 
      tr.setLayoutParams(lp); 
      View itemView = new View(this); 
      Bitmap bm = getBitmapFromUrl(array_listcreatoravatar.get(i)); 


      if(array_listmaintype.get(i).equalsIgnoreCase("text")) 
      { 
    itemView = inflater.inflate(R.layout.writescreenlowerparts, null); 
    ImageView writescreenimageview=new ImageView(this); 
    TextView writescreenposttext = new TextView(this); 
    TextView writescreenusernametext = new TextView(this); 
    TextView writescreendatetext=new TextView(this); 
    TextView writescreensourcetext=new TextView(this); 

    writescreensourcetext=(TextView)itemView.findViewById(R.id.writescreensourcetext); 
    writescreendatetext=(TextView)itemView.findViewById(R.id.writescreendatetext); 
    writescreenposttext=(TextView)itemView.findViewById(R.id.writescreenposttext); 
    writescreenusernametext=(TextView)itemView.findViewById(R.id.writescreenusernametext); 
    LayoutParams param = new LayoutParams(MyEvents.width-90, LayoutParams.WRAP_CONTENT);  
    writescreenposttext.setLayoutParams(param); 




    if(array_listsource.get(i).equalsIgnoreCase("mobile")) 
    { 
     writescreensourcetext.setText(" via mobile"); 
    } 
    else 
    { 
     writescreensourcetext.setText(""); 
    } 


    writescreenposttext.setText(""+array_listcontent.get(i)); 
    writescreenusernametext.setText(array_listcreatorname.get(i)+" at "); 
    int thisHours = calendar.getTime().getHours(); 
      if (thisHours > 12) 
      { 


       thisHours = thisHours - 12; 
       } 
       String thisH = "" + thisHours; 
      if (thisHours == 0) 
       { 
       thisH = "00"; 
       } 

       String amPM = calendar.get(Calendar.AM_PM)== 0?"AM":"PM"; 

      if(calendar.getTime().getMinutes() < 10) 
       { 
      writescreendatetext.setText(thisH + ":0" + calendar.getTime().getMinutes() + " " + amPM); 
       } 
      else 
       { 
      writescreendatetext.setText(thisH + ":" + calendar.getTime().getMinutes() + " " + amPM); 
       } 
     Log.v("#############################",dateString); 
     Log.v("----------------------", array_listcreatorname.get(i)); 
     writescreenimageview=(ImageView)itemView.findViewById(R.id.writescreenimageview); 
     writescreenimageview.setImageBitmap(bm);  
     if(isgrey==false) 
       { 
      TableRow tabttr1=new TableRow(this); 
      tabttr1.setBackgroundDrawable(getResources().getDrawable(R.drawable.topredline)); 
      tabttr1.setLayoutParams(lp); 
      tl.addView(tabttr1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
       } 
      } 
     else if(array_listmaintype.get(i).equalsIgnoreCase("image")) 
      { 
     itemView= inflater.inflate(R.layout.writeimagelayout, null); 
     TextView writescreencontent =new TextView(this); 
     TextView writescreenimagedatetext =new TextView(this); 
     TextView writescreenusernameimagetext =new TextView(this); 
     ImageView writescreenimagetypeimage=new ImageView(this); 
     ImageView writescreenbigtypeimage=new ImageView(this); 

     TextView writescreenimagesourcetext =new TextView(this); 

     writescreenimagesourcetext=(TextView) itemView.findViewById(R.id.writescreenimagesourcetext); 
     if(array_listsource.get(i).equalsIgnoreCase("mobile")) 
     { 
      writescreenimagesourcetext.setText(" via mobile"); 
     } 
     else 
     { 
      writescreenimagesourcetext.setText(""); 
     } 


     writescreencontent=(TextView) itemView.findViewById(R.id.writecaption); 
     writescreenimagetypeimage=(ImageView)itemView.findViewById(R.id.writescreenimagetypeimage); 

     writescreenbigtypeimage=(ImageView)itemView.findViewById(R.id.writescreenbigtypeimage); 



       writescreenbigtypeimage.setTag(i); 
       if(array_listcontent.get(i).length() > 1) 
       { 
       writescreencontent.setText(array_listcontent.get(i)); 
       } 

       writescreenbigtypeimage.setOnClickListener(new OnClickListener() 
       { 

        @Override 
        public void onClick(View v) 
        { 
         int j = Integer.valueOf(v.getTag().toString()); 
         Intent in=new Intent(WriteScreen.this,FullImage.class); 

         fullimage= array_listimageurl.get(j); 
         Log.v("%%%%%%%%%%%%%%%%%%%%%%%%%%%%",array_listimageurl.get(j)); 
         startActivity(in); 
        } 
       }); 

       writescreenusernameimagetext=(TextView)itemView.findViewById(R.id.writescreenusernameimagetext); 
       writescreenimagedatetext=(TextView)itemView.findViewById(R.id.writescreenimagedatetext); 
       writescreenusernameimagetext.setText(array_listcreatorname.get(i)+ " at "); 


      int thisHours = calendar.getTime().getHours(); 
      if (thisHours > 12) 
      { 
       thisHours = thisHours - 12; 
      } 
      String thisH = "" + thisHours; 
      if (thisHours == 0) 
      { 
       thisH = "00"; 
      } 

       String amPM = calendar.get(Calendar.AM_PM)== 0?"AM":"PM"; 
      // myeventstime1.setText(cDate.toGMTString().substring(cDate.toGMTString().indexOf(":")-3).trim()); 
      if(calendar.getTime().getMinutes() < 10) 
      { 
       writescreenimagedatetext.setText(thisH + ":0" + calendar.getTime().getMinutes() + " " + amPM); 
      } 
      else 
      { 
       writescreenimagedatetext.setText(thisH + ":" + calendar.getTime().getMinutes() + " " + amPM); 
      } 
       String s = array_listimageurl.get(i); 
       Bitmap bm1 = getBitmapFromUrl(s); 
       writescreenimagetypeimage.setImageBitmap(bm); 
       writescreenbigtypeimage.setLayoutParams(lpImageView); 
       writescreenbigtypeimage.setImageBitmap(bm1); 
      if(isgrey==false) 
      { 
       TableRow tabttr1=new TableRow(this); 
       tabttr1.setBackgroundDrawable(getResources().getDrawable(R.drawable.topredline)); 
       tabttr1.setLayoutParams(lp); 
       tl.addView(tabttr1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
      } 
      } 


      else if(array_listmaintype.get(i).equalsIgnoreCase("video")) 
      { 
      itemView= inflater.inflate(R.layout.writescreenvideo, null); 
      ImageView writescreenimagesmallvideotype=new ImageView(this); 
      ImageView writescreenbigvideotype=new ImageView(this); 
      TextView writescreencontentvideotype =new TextView(this); 
      TextView writescreenusernamevideotype =new TextView(this); 
      TextView writescreendateandtimevideotype =new TextView(this); 

      TextView writescreensourcevideotype =new TextView(this); 

      writescreensourcevideotype=(TextView)itemView.findViewById(R.id.writescreensourcevideotype); 
      if(array_listsource.get(i).equalsIgnoreCase("mobile")) 
      { 
       writescreensourcevideotype.setText(" via mobile"); 
      } 
      else 
      { 
       writescreensourcevideotype.setText(""); 
      } 




      writescreenimagesmallvideotype=(ImageView)itemView.findViewById(R.id.writescreenimagesmallvideotype); 
      writescreenbigvideotype=(ImageView)itemView.findViewById(R.id.writescreenbigvideotype); 

      writescreencontentvideotype=(TextView)itemView.findViewById(R.id.writescreencontentvideotype); 
      writescreenusernamevideotype=(TextView)itemView.findViewById(R.id.writescreenusernamevideotype); 
      writescreendateandtimevideotype =(TextView)itemView.findViewById(R.id.writescreendateandtimevideotype); 

      writescreencontentvideotype.setText(array_listcontent.get(i)); 
      writescreenusernamevideotype.setText(array_listcreatorname.get(i)+" at "); 


      int thisHours = calendar.getTime().getHours(); 
      if (thisHours > 12) 
      { 
       thisHours = thisHours - 12; 
      } 
      String thisH = "" + thisHours; 
      if (thisHours == 0) 
      { 
       thisH = "00"; 
      } 
      String amPM = calendar.get(Calendar.AM_PM)== 0?"AM":"PM"; 

      if(calendar.getTime().getMinutes() < 10) 
      { 
       writescreendateandtimevideotype.setText(thisH + ":0" + calendar.getTime().getMinutes() + " " + amPM); 
      } 
      else 
      { 
       writescreendateandtimevideotype.setText(thisH + ":" + calendar.getTime().getMinutes() + " " + amPM); 
      } 
      writescreenimagesmallvideotype.setImageBitmap(bm); 
      String s1 = array_listurl1.get(i); 
      Bitmap bm2 = getBitmapFromUrl(s1); 
      writescreenbigvideotype.setLayoutParams(lpImageView); 
      writescreenbigvideotype.setImageBitmap(bm2); 
      writescreenbigvideotype.setTag(i); 
      writescreenbigvideotype.setOnClickListener(new OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        int j = Integer.valueOf(v.getTag().toString()); 
        Intent in=new Intent(WriteScreen.this,WatchVideo.class); 
        in.putExtra("path", array_listurl.get(j)); 
        startActivity(in); 
       } 
      }); 

      if(isgrey==false) 
      { 
       TableRow tabttr1=new TableRow(this); 
       tabttr1.setBackgroundDrawable(getResources().getDrawable(R.drawable.topredline)); 
       tabttr1.setLayoutParams(lp); 
       tl.addView(tabttr1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
      } 

      } 
     else if(array_listmaintype.get(i).equalsIgnoreCase("audio")) 
     { 
      itemView= inflater.inflate(R.layout.writescreenaudio, null); 
      ImageView writescreenimagesmallaudiotype=new ImageView(this); 
      ImageButton writescreenbuttonaudioplay =new ImageButton(this); 
      TextView writescreencontentaudiotype =new TextView(this); 
      TextView writescreenusernameaudiotype =new TextView(this); 
      //TextView writescreendateandtimeaudiotype =new TextView(this); 
      ImageButton writescreenbuttonaudiostop =new ImageButton(this); 
      TextView writescreendurationaudiotype =new TextView(this); 
      TextView writescreendtimeaudiotype =new TextView(this); 
      TextView writescreensourceaudiotype =new TextView(this); 

      writescreenbuttonaudiostop=(ImageButton)itemView.findViewById(R.id.writescreenbuttonaudiostop); 
      writescreensourceaudiotype=(TextView) itemView.findViewById(R.id.writescreensourceaudiotype); 

      if(array_listsource.get(i).equalsIgnoreCase("mobile")) 
      { 
      writescreensourceaudiotype.setText(" via mobile"); 
      } 
      else 
      { 
      writescreensourceaudiotype.setText(""); 
      } 

      writescreendurationaudiotype=(TextView)itemView.findViewById(R.id.writescreendurationaudiotype); 


       writescreendurationaudiotype.setText(array_listaudiodurationurl.get(i)); 
       writescreenbuttonaudioplay=(ImageButton)itemView.findViewById(R.id.writescreenbuttonaudioplay); 
      writescreenbuttonaudioplay.setTag(i); 
      writescreenbuttonaudioplay.setOnClickListener(new OnClickListener() 
      { 
       @Override 
       public void onClick(View v) 
       { 
        int j = Integer.valueOf(v.getTag().toString()); 
        String path=array_listaudiourl.get(j); 
        mediaPlayer = new MediaPlayer(); 
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
        try 
        { 
        mediaPlayer.setDataSource(path); 
        } 
        catch (IllegalArgumentException e) 
        { 
        e.printStackTrace(); 
        } 
        catch (IllegalStateException e) 
        { 
        e.printStackTrace(); 
        } 
        catch (IOException e) 
        { 
        e.printStackTrace(); 
        } 
        try 
        { 
        mediaPlayer.prepare(); 
        } 
        catch (IllegalStateException e) 
        { 
        e.printStackTrace(); 
        } 
        catch (IOException e) 
        { 
        e.printStackTrace(); 
        } 
        mediaPlayer.start(); 
        mediaPlayer.setOnCompletionListener(new OnCompletionListener() 
        { 
         @Override 
         public void onCompletion(MediaPlayer paramMediaPlayer) 
         { 
          mediaPlayer.stop(); 
         } 
        }); 
       } 
      }); 
      writescreenbuttonaudiostop.setOnClickListener(new OnClickListener() 
      { 
       @Override 
       public void onClick(View paramView) 
       {  
        if(mediaPlayer!=null&& mediaPlayer.isPlaying()) 
        { 
        mediaPlayer.stop(); 
       } 
       } 
      }); 
       writescreenimagesmallaudiotype=(ImageView)itemView.findViewById(R.id.writescreenimagesmallaudiotype);  
       writescreenimagesmallaudiotype.setImageBitmap(bm); 

       writescreencontentaudiotype=(TextView) itemView.findViewById(R.id.writescreencontentaudiotype); 
       writescreencontentaudiotype.setText(array_listcontent.get(i)); 

       writescreenusernameaudiotype=(TextView) itemView.findViewById(R.id.writescreenusernameaudiotype); 
       writescreenusernameaudiotype.setText(array_listcreatorname.get(i)+" at "); 

       writescreenbuttonaudiostop=(ImageButton)itemView.findViewById(R.id.writescreenbuttonaudiostop); 


       writescreendtimeaudiotype=(TextView)itemView.findViewById(R.id.writescreendtimeaudiotype); 
       int thisHours = calendar.getTime().getHours(); 
       if (thisHours > 12) 
       { 
        thisHours = thisHours - 12; 
       } 
       String thisH = "" + thisHours; 
       if (thisHours == 0) 
       { 
        thisH = "00"; 
       } 
       String amPM = calendar.get(Calendar.AM_PM)== 0?"AM":"PM"; 
       // myeventstime1.setText(cDate.toGMTString().substring(cDate.toGMTString().indexOf(":")-3).trim()); 
       if(calendar.getTime().getMinutes() < 10) 
       { 
        writescreendtimeaudiotype.setText(thisH + ":0" + calendar.getTime().getMinutes() + " " + amPM); 
       } 
       else 

       { 
        writescreendtimeaudiotype.setText(thisH + ":" + calendar.getTime().getMinutes() + " " + amPM); 
       } 
       if(isgrey==false) 
       { 
        TableRow tabttr1=new TableRow(this); 
        tabttr1.setBackgroundDrawable(getResources().getDrawable(R.drawable.topredline)); 
        tabttr1.setLayoutParams(lp); 
        tl.addView(tabttr1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
       }   
     } 
      tr.addView(itemView); 
      tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 

      isgrey=false; 
     } 
     } 
    } 

    public Drawable getDrawableFromUrl(String url) 
    { 
     try{ 
      InputStream is = (InputStream) new URL(url).getContent(); 
      Drawable d = Drawable.createFromStream(is,"img"); 
      return d; 
     } 
     catch (Exception e) { 
      // TODO: handle exception 
     return null; 
     } 
    } 
    public Bitmap getBitmapFromUrl(String url) 
    { 
    HttpGet httpRequest = null;  
     httpRequest = new HttpGet(url); 
     Log.v("----------------------", url); 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpResponse response = null; 
      try 
      { 
     response = (HttpResponse) httpclient.execute(httpRequest); 

      }   
      catch (ClientProtocolException e) 
      { 

      e.printStackTrace(); 

      } 
      catch (IOException e) 
      { 
     e.printStackTrace(); 
     } 
     HttpEntity entity = response.getEntity(); 
     BufferedHttpEntity bufHttpEntity = null; 
     try 
     { 
      bufHttpEntity = new BufferedHttpEntity (entity); 
     }  
     catch (IOException e) 
     { 

      e.printStackTrace(); 
     } 
     InputStream instream = null; 
     try 
     { 
      instream = bufHttpEntity.getContent(); 
     }  
     catch (IOException e) 
     { 

      e.printStackTrace(); 
     } 
     Bitmap bm = BitmapFactory.decodeStream(instream); 
     return bm; 
    } 

    public void writescreen() throws ClientProtocolException, IOException, JSONException 
    { 
     HttpClient client = new DefaultHttpClient(); 
     String un = android.util.Base64.encodeToString(username.getBytes("UTF-8"),android.util.Base64.NO_WRAP); 
     String ps = android.util.Base64.encodeToString(password.getBytes("UTF-8"),android.util.Base64.NO_WRAP); 
      AuthScope as = new AuthScope(hostSecure,443); 
      UsernamePasswordCredentials upc = new UsernamePasswordCredentials(un,ps); 
      String auth = android.util.Base64.encodeToString((username + ":" + password).getBytes("UTF-8"),android.util.Base64.NO_WRAP); 
      ((AbstractHttpClient) client).getCredentialsProvider() .setCredentials(as, upc); 
      BasicHttpContext localContext = new BasicHttpContext(); 
      BasicScheme basicAuth = new BasicScheme(); 
      localContext.setAttribute("preemptive-auth", basicAuth); 
      HttpHost targetHost = new HttpHost(hostSecure, 443, "https"); 
      HttpGet httpget = new HttpGet("https://apiv1secure.somedomain.com/event/"+eId+"/page?Token=RCFB3m4W"+ "&format=json"); 
      httpget.addHeader("Authorization", "Basic "+ auth); 
      HttpResponse response = client.execute(targetHost, httpget, localContext); 
      HttpEntity entity = response.getEntity(); 
      Object content = EntityUtils.toString(entity); 
      Log.e("", "----------------------------------------"+content); 
      json = new JSONObject(content.toString()); 


      JSONArray s = null; 

      s = json.getJSONArray("Posts"); 

      for(int i = 0; i< s.length();i++) 
     { 
       String a = s.getString(i); 
       JSONObject jt = new JSONObject(a); 
       String postid=jt.getString("Id"); 
       if(jt.has("Content")) 
       { 
        String postcontent=jt.getString("Content"); 
        array_listcontent.add(postcontent); 
       } 
       else 
       { 
        array_listcontent.add(""); 
       } 

       String creator = jt.getString("Creator"); 
       array_listid.add(postid); 

       JSONObject jt1 = new JSONObject(creator); 
       String creatorid = jt1.getString("Id"); 
       String creatoravatar=jt1.getString("Avatar"); 
       String creatorname=jt1.getString("Name"); 
       array_listcreatorname.add(creatorname); 
       array_listcreatorid.add(creatorid); 
       array_listcreatoravatar.add(creatoravatar); 

       mainType=jt.getString("Type"); 
       array_listmaintype.add(mainType); 

       lastmodified=jt.getString("LastModified"); 
       array_listlastmodified.add(lastmodified); 

       String createddate=jt.getString("Created"); 
       array_listcreated .add(createddate); 

       source=jt.getString("Source"); 
       array_listsource.add(source); 




       if(mainType.equalsIgnoreCase("image")) 
       { 
        String Media = ""; 

        if(jt.has("Media")) 
        { 
        JSONArray mediatype = jt.getJSONArray("Media"); 
        String d = mediatype.getString(0); 
        JSONObject jmediatype = new JSONObject(d); 
        d = mediatype.getString(0); 
        jmediatype = new JSONObject(d); 
         imagetype = jmediatype.getString("Type"); 
        String imageurl=jmediatype.getString("Url"); 
        array_listimagetype.add(imagetype); 
        array_listimageurl.add(imageurl); 
        array_listtype1.add("0"); 
        array_listurl1.add("0"); 
        array_listduration.add("0"); 
        array_listurl.add("0"); 
        array_listtype.add("0"); 
        array_listaudiourl.add("0"); 
        array_listaudiodurationurl.add("0"); 
        } 
       } 
       else if (mainType.equalsIgnoreCase("video")) 
       { 
        String Media = ""; 
        if(jt.has("Media")) 
      { 
        JSONArray mediatype= jt.getJSONArray("Media"); 
        String d = mediatype.getString(0); 
        JSONObject jmediatype = new JSONObject(d); 
        String type=jmediatype.getString("Type"); 
        String url=jmediatype.getString("Url"); 
        String durationtype=jmediatype.getString("Duration"); 
        array_listduration.add(durationtype); 
        array_listurl.add(url); 
        array_listtype.add(type); 

        d = mediatype.getString(1); 
        jmediatype = new JSONObject(d); 
        String type1 = jmediatype.getString("Type"); 
        String url1=jmediatype.getString("Url"); 
        array_listtype1.add(type1); 
        array_listurl1.add(url1); 

        array_listimagetype.add("0"); 
        array_listimageurl.add("0"); 
        array_listaudiourl.add("0"); 
        array_listaudiodurationurl.add("0"); 
        } 
       } 
       else if (mainType.equalsIgnoreCase("text")) 
       { 
        array_listimagetype.add("0"); 
        array_listimageurl.add("0"); 
        array_listtype1.add("0"); 
        array_listurl1.add("0"); 
        array_listduration.add("0"); 
        array_listurl.add("0"); 
        array_listtype.add("0"); 
        array_listaudiourl.add("0"); 
        array_listaudiodurationurl.add("0"); 
       } 
       else if(mainType.equalsIgnoreCase("audio")) 
       { 
        JSONArray mediatype= jt.getJSONArray("Media"); 
        String d = mediatype.getString(0); 
        JSONObject jmediatype = new JSONObject(d); 
        String audiourl=jmediatype.getString("Url"); 
        String audioduration=jmediatype.getString("Duration"); 
        array_listaudiourl.add(audiourl); 
        array_listaudiodurationurl.add(audioduration); 

        array_listimagetype.add("0"); 
        array_listimageurl.add("0"); 
        array_listtype1.add("0"); 
        array_listurl1.add("0"); 
        array_listduration.add("0"); 
        array_listurl.add("0"); 
        array_listtype.add("0"); 

       } 
    } 
} 
+0

시도해 보셨습니까? IMO는 리소스가 사전 처리되어 (성능상의 이유로) apk에 바이너리 형식으로 저장되기 때문에 작동하지 않습니다. –

+0

틀렸어. 앱을 완전히 동적으로로드했습니다. 이유는 너무 많은 리소스가 apk 크기를 50MB 이상으로 늘리고 있기 때문입니다. 대답이 정확하지 않을 경우 투표를하지 말아야합니다. –

+0

확인. 네트워크에서 간단한 레이아웃 XML을로드하는 코드를 보여줍니다 (이미지뿐 아니라 .. 등). 당신의 대답에 그것을 추가하면 내가 당신을 upvote거야. –

0

가 없음이 불가능는. LayoutInflater에는 명확하게 (세 번째 단락).

그러나 네트워크에서 비트 맵과 텍스트를로드하고 직접 삽입 할 수 있습니다. 그러나 레이아웃 리소스를로드하고 팽창시킬 수 없습니다.

+0

당신은 당신의 약속을 잊었습니까 ??? –

+0

OP는 "모든 리소스를 온라인에서로드 할 수 있음"을 나타냅니다. 모든 리소스를로드 할 수 없습니다. 가장 중요한 것은 레이아웃 리소스입니다. 또한 로컬 리소스를 팽창시켜 외부 리소스 (네트워크에서로드 됨)를 사용할 수 없습니다. 당신이 제안하는 것은 명백합니다 : 내부 자원을 부 풀리고 모든 속성과 외부 자원을 수동으로 설정하십시오. IMO, OP가 요구 한 것이 아닙니다.나는 같은 대답을했다. 어쨌든, 당신은 1 차 답안에이 점을 충분히 진술하고 올바르게 읽지 않았으므로 -1을 제거합니다. 하지만 당신은 +1 할 가치가 없습니다. –

+0

@Shourab : 아, 네, 정답에 -1 주셔서 감사합니다. 또는 나는 어느 시점에서 잘못 되었습니까? –

관련 문제