如何让我的“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();
}
}
答案 0 :(得分:0)
试试Re-using Layouts with include。这将允许您使用相同的布局代码。如何将布局创建两次。将其视为对象继承。另一种方法是使用addView和removeView。在这种情况下,您将使用相同的对象,并且它在内存使用方面更有效率,但创建起来更复杂。