0

如何让我的“sodrzina”显示在其他 xml 布局上。你可以看到我用 setContentView(R.layout.sodrzina); 尝试了几次。.. 使用这些方法,我在点击时打开其他布局,但没有内容。如何在那里显示我的内容?

         View.OnClickListener 
        getOnClickDoSomething(final Button button)  {
    return new View.OnClickListener() {         
    public void onClick (View v){
        //TextView View = (TextView) findViewById(R.id.viewSodrzina);
        setContentView(R.layout.sodrzina);
         TextView View = (TextView) findViewById(R.id.viewSodrzina);
         String sodrzina="";
    }

    }
        String sodrzina="";

    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.cook-recipes.hostoi.com/jsonscript/sodrzina.php?sodrzina="+(button.getText()).toString().replace(" ","%20"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream webs = entity.getContent();

        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);
            //myListView.setText(reader.readLine());

            int askiChar=0;
            while((askiChar =reader.read())!=-1)
            {
            sodrzina+= ((char)askiChar);
            }
            webs.close();
            reader.close();

        }catch(Exception e){
            Log.e("log_tag","Error converting reslt"+e.toString());
        }

        //TextView prikaziSodrzina = (TextView)findViewById(R.id.viewSodrzina);
        //Toast.makeText(Desert.this,sodrzina, Toast.LENGTH_LONG).show();
        //prikaziSodrzina.append(sodrzina);

    //  View.append(sodrzina);



    }
    catch (Exception e)
    {
        Log.e("ERROR","ERROR IN CODE: "+e.toString());
        e.printStackTrace();
    }
    }
4

1 回答 1

0

尝试通过 include 重用布局。这将允许您使用相同的布局代码。无论如何,布局将被创建两次。将其视为对象继承。另一种方法是使用addViewremoveView。在这种情况下,您将使用相同的对象,并且在内存使用方面更有效,但创建起来更复杂。

于 2013-04-21T11:57:55.077 回答