开发者

how to display items one after one in custom layout using Asynocronous task in android

i am creating one layout in code retrieve all message string and image using webservices all retrieve data in background process display the data total all views display one time ,

my intension is i am getting one message string and one image getting after display custom layout next getting another(second) message string and image then display add the layout this functionality running one by one show the messages and images

xmlfile:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/frameLayout1"     
 android:layout_width="fill_parent"     
 android:background="@android:color/white"   
   android:layout_height="fill_parent">   
  <ScrollView android:id="@+id/scrollView1"   
       android:layout_height="wrap_content"  
        android:layout_width="fill_parent">  
    </ScrollView>
 </FrameLayout> 

code file :

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1); 

    LinearLayout topLinearLayout = new LinearLayout(this); 
    topLinearLayout.setOrientation(LinearLayout.VERTICAL);  

    for (int i = 0; i < 15; i++){ 

        LinearLayout linearLayout = new LinearLayout(this); 
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);  

        ImageView imageView = new ImageView (this); 
        TextView textView = new TextView (this); 

        imageView.setImageResource(R.drawable.image); 
        textView.setText("Text View #" + i); 

        linearLa开发者_StackOverflow中文版yout.addView(imageView); 
        linearLayout.addView(textView); 

        topLinearLayout.addView(linearLayout);           

    } 

    scrollView.addView(topLinearLayout); 

} 

how can display image and message in custom layout one after one in dynamically please forward some solution thank in advance


using asynronous task in u r application update to ui

http://developer.android.com/reference/android/os/AsyncTask.html


The best way to do this(in my point of view) is to create a ListView with an custom Adapter (extend BaseAdapter, see documentation) and when you get another assynchronous message update the data on the list and call notifyDataSetChanged() from the adapter to redraw the list.

You are not doing the way it is supposed to be in Android.

Hope it helped!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜