在列表中单独列的显示数据 [英] display data in seperate columns in list
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/8395750/nullpointerexception-in-multi-column-list\">nullPointerException多列列表
我有以下的应用程序从URL获取数据并显示。
I have following app which fetches data from URL and displays it.
问题是我得到的名单,其输出由不同行的。
The problem is I get the output in list which consists of various rows.
现在我要行数据为4列分割如下。
Now I want to split the row data into 4 columns as below.
SBIN; 1911.05; 1886.85; 1.28
应显示为4列(由分隔';')的1行内,而不是作为单个元件。看到这个截图,以供参考:
SBIN ;1911.05;1886.85;1.28
should be displayed as 4 columns(seperated by ';') within 1 row and not as a single element. See this screenshot for reference:
ReadWebPageAsyncTask.java
public class ReadWebpageAsyncTask extends Activity {
private EditText ed;
private ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed = (EditText) findViewById(R.id.ed);
lv = (ListView) findViewById(R.id.list);
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://abc.com/default.aspx?id=G" });
}
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
@Override
protected void onPostExecute(String result) {
int sub = result.lastIndexOf('@', result.length() - 1);
String s1 = result.substring(0, sub);
String s = s1.replace(";", " - ");
String arr[] = s.split("@");
lv.setAdapter(new ArrayAdapter<String>(ReadWebpageAsyncTask.this,
android.R.layout.simple_list_item_1, arr));
}
}
}
请检查此链接的
PLEASE CHECK THIS LINK
<一个href=\"http://stackoverflow.com/questions/8395750/java-lang-illegalstateexception-the-specified-child-already-has-a-parent\">nullPointerException多列列表
它使用多列列表这种方式是非常忙碌的。相反,我试过<一个href=\"http://stackoverflow.com/questions/8411101/nullpointerexception-in-multi-column-list-using-hashmap\">this和它的工作。
It is very hectic using multi column list this way. Instead I tried this and it worked..
推荐答案
使用Android表格布局
Use android table layout
这篇关于在列表中单独列的显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!