我正在创建一个代码布局检索所有的消息字符串和图像使用webservices所有检索数据在后台进程显示数据总数所有视图显示一次,
我的意图是我得到一个消息字符串和一个图像后显示自定义布局下得到另一个(第二个)消息字符串和图像然后显示添加布局这个功能一个接一个运行显示消息和图像
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>
代码文件:
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);
linearLayout.addView(imageView);
linearLayout.addView(textView);
topLinearLayout.addView(linearLayout);
}
scrollView.addView(topLinearLayout);
}
如何在自定义布局中一个接一个地动态显示图像和消息请转发一些解决方案,谢谢提前
using asynronous task in u r application update to ui
http://developer.android.com/reference/android/os/AsyncTask.html
这样做的最好方法(在我看来)是创建一个ListView与自定义适配器(扩展BaseAdapter,见文档),当你得到另一个异步消息更新列表上的数据和调用notifyDataSetChanged()从适配器重新绘制列表。
你没有按照Android应该的方式去做。
希望有帮助!