Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display string response from db as one by one in Android?

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.

like image 268
prasad.gai Avatar asked Nov 04 '22 14:11

prasad.gai


1 Answers

What you can do is display the Listview without waiting for response and from background thread add the responses to messages and call

mAdapter.notifyDatasetChanged();

This is concept of LazyLoading and I hope it should work

Update

runOnUiThread(new Runnable() {
public void run() {
    adapter.notifyDataSetChanged();
}
});
like image 57
ingsaurabh Avatar answered Nov 09 '22 09:11

ingsaurabh