如何在Android中将数据库的字符串响应一一显示?
我是 Android 的新开发者。我正在我的应用程序中使用soap对象与.net数据库服务进行通信。我从数据库服务器获取字符串形式的响应。但我的意图是,当我从数据库服务器获取字符串作为响应时,然后立即查看为文本视图,类似地,我正在获取图像编码字符串。如何立即获取响应作为视图。我编写的代码如下:
String xml="<spGetUserMessages><SearchLocation></SearchLocation><LoginUserID>"+Userid+"</LoginUserID></spGetUserMessages>";
我将请求作为 XML 发送到数据库服务器
数据库服务器的响应在列表中:
List<MessageClass> response=new ParseXml().getUserMessages(new Generic().getMessages(xml));
String messages=new String[response.size()];
for(int i=0;i<response.size();i++)
{
//the response values are saved in messages array
messages[i]=response.get(i).getmessage();
}
我在该类中编写了一个基本适配器类,我们有一个 getView 方法实现如下:
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
Log.v("rrrrrrrrrr", "rrrrrrrr"+messages[position]);
text.setText(messages[position]);
}
根据上面的代码,我一次显示所有消息。但在这种情况下,响应需要时间,然后我就会出现黑屏。这里我的意图是,当我收到字符串响应时,我将在下次类似地将该字符串视为文本视图,直到响应大小完成。
I am new developer in android. I am working with soap object in my application for communicate with the .net db services.I am getting response as strings from DB server. But my intention is when I get a string from db server as response then imediatly view as text view similarly I am getting images encoded string.how to get response imedialty as view. I have written code as follows:
String xml="<spGetUserMessages><SearchLocation></SearchLocation><LoginUserID>"+Userid+"</LoginUserID></spGetUserMessages>";
I am sending request as XML to db server
The response from db server is in list:
List<MessageClass> response=new ParseXml().getUserMessages(new Generic().getMessages(xml));
String messages=new String[response.size()];
for(int i=0;i<response.size();i++)
{
//the response values are saved in messages array
messages[i]=response.get(i).getmessage();
}
I have written a base adapter class in that class we have a method as getView I have implemented as follows:
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
Log.v("rrrrrrrrrr", "rrrrrrrr"+messages[position]);
text.setText(messages[position]);
}
From the above code I am displaying all messages at a time. But in this situation the response is taking time then I am getting blank screen. Here my intention is when I get a string response then I will view that string as text view next time next similarly untill reposnse size has completed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做的是显示 Listview,而不等待响应,并从后台线程将响应添加到
messages
并调用这是
LazyLoading
的概念,我希望它能够工作更新
What you can do is display the Listview without waiting for response and from background thread add the responses to
messages
and callThis is concept of
LazyLoading
and I hope it should workUpdate
使用 AsyncTask 类以这种方式在后台进程中工作
use the AsyncTask class to work in background process like this way