<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>View Account</title></head>
<body>
<form action="viewaccount" method="post"><p>anything</p> <br/>
<strong ><font face="Tahoma" color="#336666" >Your User Name is: Kelly
</font></strong>
<INPUT TYPE=hidden NAME="username" VALUE="Kelly"> <font face="Tahoma" >User Name: Kelly</font><br/>
<font face="Tahoma" >Telephone:88888888</font><br/>
<font face="Tahoma" >Email:kelly@gmail.com</font><br/>
<br/>
<a href="success.jsp">Back</a>
</form></body>
</html>
是一个html文件
我怎样才能把文件里的内容在Android端显示出来呢?
或者怎么可以直接返回我所需要的数据?
刚刚学起Android,各位帮忙啊,急啊
3 个解决方案
#1
建议以XML格式返回数据,Android端放置好TextView等控件,然后再从XML中找到数据填入控件中就好了
#2
因为我的server端之前做好了,用的是HTML显示的 所以现在想直接看看能不能直接显示在客户端。
有没有例子啊,学习一下,返回XML的也可以
有没有例子啊,学习一下,返回XML的也可以
#3
不管返回的是HTML、XML、TXT或者其他格式,只要你知道这个返回里面哪个位置有你想要的数据就可以了。
比如你上面的那个返回数据,你是不是想在客户端显示:
Your User Name is: Kelly
User Name: Kelly
Telephone:88888888
Email:kelly@gmail.com
package org.abcd.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String htmlStr="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>View Account</title></head><body><form action=\"viewaccount\" method=\"post\"><p>anything</p> <br/><strong ><font face=\"Tahoma\" color=\"#336666\" >Your User Name is: Kelly</font></strong><INPUT TYPE=hidden NAME=\"username\" VALUE=\"Kelly\"> <font face=\"Tahoma\" >User Name: Kelly</font><br/> <font face=\"Tahoma\" >Telephone:88888888</font><br/> <font face=\"Tahoma\" >Email:kelly@gmail.com</font><br/> <br/><a href=\"success.jsp\">Back</a></form></body></html>";
TextView tv1 = new TextView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(tv1);
addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
int strStart,strEnd;
String yourname, username, telephone, email;
strStart = htmlStr.indexOf(">Your") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
yourname = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf(">User") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
username = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Telephone");
strEnd = htmlStr.indexOf("</font>", strStart);
telephone = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Email");
strEnd = htmlStr.indexOf("</font>", strStart);
email = htmlStr.substring(strStart, strEnd);
tv1.setText(yourname + "\n" + username +"\n" + telephone +"\n" + email);
}
}
比如你上面的那个返回数据,你是不是想在客户端显示:
Your User Name is: Kelly
User Name: Kelly
Telephone:88888888
Email:kelly@gmail.com
package org.abcd.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String htmlStr="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>View Account</title></head><body><form action=\"viewaccount\" method=\"post\"><p>anything</p> <br/><strong ><font face=\"Tahoma\" color=\"#336666\" >Your User Name is: Kelly</font></strong><INPUT TYPE=hidden NAME=\"username\" VALUE=\"Kelly\"> <font face=\"Tahoma\" >User Name: Kelly</font><br/> <font face=\"Tahoma\" >Telephone:88888888</font><br/> <font face=\"Tahoma\" >Email:kelly@gmail.com</font><br/> <br/><a href=\"success.jsp\">Back</a></form></body></html>";
TextView tv1 = new TextView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(tv1);
addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
int strStart,strEnd;
String yourname, username, telephone, email;
strStart = htmlStr.indexOf(">Your") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
yourname = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf(">User") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
username = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Telephone");
strEnd = htmlStr.indexOf("</font>", strStart);
telephone = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Email");
strEnd = htmlStr.indexOf("</font>", strStart);
email = htmlStr.substring(strStart, strEnd);
tv1.setText(yourname + "\n" + username +"\n" + telephone +"\n" + email);
}
}
#1
建议以XML格式返回数据,Android端放置好TextView等控件,然后再从XML中找到数据填入控件中就好了
#2
因为我的server端之前做好了,用的是HTML显示的 所以现在想直接看看能不能直接显示在客户端。
有没有例子啊,学习一下,返回XML的也可以
有没有例子啊,学习一下,返回XML的也可以
#3
不管返回的是HTML、XML、TXT或者其他格式,只要你知道这个返回里面哪个位置有你想要的数据就可以了。
比如你上面的那个返回数据,你是不是想在客户端显示:
Your User Name is: Kelly
User Name: Kelly
Telephone:88888888
Email:kelly@gmail.com
package org.abcd.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String htmlStr="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>View Account</title></head><body><form action=\"viewaccount\" method=\"post\"><p>anything</p> <br/><strong ><font face=\"Tahoma\" color=\"#336666\" >Your User Name is: Kelly</font></strong><INPUT TYPE=hidden NAME=\"username\" VALUE=\"Kelly\"> <font face=\"Tahoma\" >User Name: Kelly</font><br/> <font face=\"Tahoma\" >Telephone:88888888</font><br/> <font face=\"Tahoma\" >Email:kelly@gmail.com</font><br/> <br/><a href=\"success.jsp\">Back</a></form></body></html>";
TextView tv1 = new TextView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(tv1);
addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
int strStart,strEnd;
String yourname, username, telephone, email;
strStart = htmlStr.indexOf(">Your") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
yourname = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf(">User") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
username = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Telephone");
strEnd = htmlStr.indexOf("</font>", strStart);
telephone = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Email");
strEnd = htmlStr.indexOf("</font>", strStart);
email = htmlStr.substring(strStart, strEnd);
tv1.setText(yourname + "\n" + username +"\n" + telephone +"\n" + email);
}
}
比如你上面的那个返回数据,你是不是想在客户端显示:
Your User Name is: Kelly
User Name: Kelly
Telephone:88888888
Email:kelly@gmail.com
package org.abcd.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String htmlStr="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>View Account</title></head><body><form action=\"viewaccount\" method=\"post\"><p>anything</p> <br/><strong ><font face=\"Tahoma\" color=\"#336666\" >Your User Name is: Kelly</font></strong><INPUT TYPE=hidden NAME=\"username\" VALUE=\"Kelly\"> <font face=\"Tahoma\" >User Name: Kelly</font><br/> <font face=\"Tahoma\" >Telephone:88888888</font><br/> <font face=\"Tahoma\" >Email:kelly@gmail.com</font><br/> <br/><a href=\"success.jsp\">Back</a></form></body></html>";
TextView tv1 = new TextView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(tv1);
addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
int strStart,strEnd;
String yourname, username, telephone, email;
strStart = htmlStr.indexOf(">Your") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
yourname = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf(">User") + 1;
strEnd = htmlStr.indexOf("</font>", strStart);
username = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Telephone");
strEnd = htmlStr.indexOf("</font>", strStart);
telephone = htmlStr.substring(strStart, strEnd);
strStart = htmlStr.indexOf("Email");
strEnd = htmlStr.indexOf("</font>", strStart);
email = htmlStr.substring(strStart, strEnd);
tv1.setText(yourname + "\n" + username +"\n" + telephone +"\n" + email);
}
}