【问题标题】:Redirect my Text View to other layout将我的文本视图重定向到其他布局
【发布时间】:2013-04-21 11:39:13
【问题描述】:

如何让我的“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();
    }
    }

【问题讨论】:

    标签: android android-layout android-intent onclick xml-layout


    【解决方案1】:

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

    【讨论】:

    • 但是这些内容是由动态按钮生成的,我需要代码帮助
    • 我自己解决了 :D 我做了获取布局方法并将 id 从新布局放在文本视图上。所以现在一切正常。谢谢大家
    猜你喜欢
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 2017-05-10
    相关资源
    最近更新 更多