完成后的AsyncTask的ListView更新 [英] ListView update after complete AsyncTask
问题描述
我想用的AsyncTask更新的TextView的文本。
我在该列表视图有两个TextView的,一个是ImageView的
当用户preSS的ImageView按钮宋会从服务器端进行播放。所以,我已经把code中的AsyncTask任务
这是从我打电话的ImageView,请点击下面的事件的自定义适配器是我的code样品这样
公共查看getView(最终诠释的立场,观点convertView,
父母的ViewGroup){ holder.imgPlay.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){
和onclick事件我传递的TextView在AsyncTask的,我想从互联网上所以下面获取数据后更改我的code
新MetadataTask2()执行(holder.txtMetadata);
现在的AsyncTask的code低于
类MetadataTask2扩展的AsyncTask< TextView的,无效的,IcyStreamMeta> {
TextView的txtView; @覆盖
保护IcyStreamMeta doInBackground(
TextView中......为arg0){
//某项操作
txtView = arg0都[0];
返回streamMeta;
} @覆盖
保护无效onPostExecute(IcyStreamMeta结果){
txtView.setText(Hiiiiiiii);
} @覆盖
在preExecute保护无效(){
super.on preExecute();
尝试{
PD = ProgressDialog.show(CompaniesList.this,调整......
请稍候...);
}赶上(例外五){
e.printStackTrace();
}
}
}
现在这里u可以看出,随着textView.setText(HIII)文本将被更新,但它不会在列表视图反映,我必须更新的ListView或适配器,但不知道怎么做,这样我就可以见列表视图文本任何机构可以帮助我
我用下面code更新列表视图,但仍无助
adapter.notifyDataSetChanged();
mainListView.setAdapter(适配器);
mainListView.invalidate();
您应该实现你自己的的ListView
适配器将提供数据的列表视图。调用 notifyDataSetChanged()
在 PostExecute()
从适配器将强制列表视图从适配器获取数据。更新列表视图中的观点直接看起来怪怪的。
I want to update TextView's text using AsyncTask.
I have list view in that there is Two TextView and one is ImageView
When user press ImageView button the Song will be played from server side. So i have put code in AsyncTask task
This is an custom Adapter from that i am calling ImageView's on Click event below is my code sample like this
public View getView(final int position, View convertView,
ViewGroup parent) {
holder.imgPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
and onclick event i am passing textview in asynctask, that i want to change after getting data from internet so below is my code
new MetadataTask2().execute(holder.txtMetadata);
now AsyncTask's Code is below
class MetadataTask2 extends AsyncTask<TextView, Void, IcyStreamMeta> {
TextView txtView;
@Override
protected IcyStreamMeta doInBackground(
TextView... arg0) {
//SOME OPERATION
txtView = arg0[0];
return streamMeta;
}
@Override
protected void onPostExecute(IcyStreamMeta result) {
txtView.setText("Hiiiiiiii");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
try {
PD = ProgressDialog.show(CompaniesList.this, "Tuning...",
"Please Wait...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now here u can see that with textView.setText("Hiii") the text will be updated but it will not reflect in Listview for that i have to update ListView or Adapter but do not know how to do that so i can see text on listview can any body help me
i have used below code for updating listview but still does nothing
adapter.notifyDataSetChanged();
mainListView.setAdapter(adapter);
mainListView.invalidate();
You should implement you own ListView
Adapter that will provide data to the list view. Calling notifyDataSetChanged()
in PostExecute()
from adapter will force list view to fetch data from the adapter. Updating list view views directly looks strange.
这篇关于完成后的AsyncTask的ListView更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!