次のファイルをタブの1つにロードするタブホストがあります
package com.api.view;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import com.api.api.api;
import com.api.app.R;
import com.api.communication.reports;
import com.api.sync.data.reportsList;
import com.api.tools.serverCommunication;
import com.api.tools.urlbuilder;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class EquipmentTabHistory extends Activity{
ListView lv;
ListViewAdapter adapter;
ArrayList<HashMap<String, String>> menuItems;
ProgressDialog pDialog;
static final String KEY_ITEM = "item"; // parent node
static final String KEY_ID = "id";
static final String KEY_NAME = "name";
private class ListViewAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private LayoutInflater inflater=null;
public ListViewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_item, null);
TextView name = (TextView)vi.findViewById(R.id.name);
HashMap<String, String> item = new HashMap<String, String>();
item = data.get(position);
//Setting all values in listview
name.setText(item.get("name"));
return vi;
}
}
private class loadMoreListView extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... unused) {
try {
reportsList al;
int eid = Integer.parseInt(getIntent().getStringExtra("eid"));
String[][] surl = new String[1][2];
surl[0][0] = "eid";
surl[0][1] = ""+eid;
String url;
url = urlbuilder.buildurl("getEquipmentHistory", surl);
api.debug("com.api.view.EquipmentTabHistory","URL: "+url,"info");
String pull = serverCommunication.pull(url);
reports reports;
reports = new reports(pull);
for(int i=0;i<reports.getList().size();i++){
al = reports.getList().get(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_ID,reports.getList().get(i).did);
long timestamp = Integer.parseInt(al.date) * 1000; // msec
java.util.Date d = new java.util.Date(timestamp);
map.put(KEY_NAME,al.ReportId + " - "+al.Typ + " - " + al.description + "("+d.getMonth()+". "+cT(d.getDay())+" "+(1900 + d.getYear())+" - "+d.getHours()+":"+cT(d.getMinutes())+")");
menuItems.add(map);
}
} catch (Exception e) {
api.debug("com.api.view.EquipmentTabHistory","NSAE: "+e.getMessage(),"error");
}
return (null);
}
private String cT(int time){
String r = "";
r += (time>9)?time:(time>0)?"0"+time:time;
return r;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.api_tab_history);
lv = (ListView) findViewById(R.id.listViewEquipment);
menuItems = new ArrayList<HashMap<String, String>>();
adapter = new ListViewAdapter(this, menuItems);
lv.setAdapter(adapter);
new loadMoreListView().execute();
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
api.debug("com.api.view.EquipmentTabHistory","Clicked: "+arg2+"-"+arg3,"warn");
api.debug("com.api.view.EquipmentTabHistory","Clicked: "+((TextView)findViewById(R.id.name)).getText().toString(),"warn");
api.debug("com.api.view.EquipmentTabHistory","Selected: "+menuItems.get(arg2).get(KEY_ID),"warn");
String[][] surl = new String[2][2];
surl[0][0] = "did";
surl[0][1] = menuItems.get(arg2).get(KEY_ID);
surl[1][0] = "eid";
surl[1][1] = getIntent().getStringExtra("eid");
String docurl;
try {
docurl = urlbuilder.buildurlNoXml("getDocument",surl,true);
api.debug(com.api.view.EquipmentTabHistory.class.toString(),"URL: "+docurl,"info");
System.out.println(docurl);
Intent browser = new Intent(Intent.ACTION_VIEW , Uri.parse( docurl ) );
startActivity(browser);
} catch (NoSuchAlgorithmException e) {
api.debug("com.api.view.EquipmentTabHistory","No Such Algorithm "+e.getMessage(),"error");
}
}
});
}
}
ページは例外なく読み込まれます。ログ(api.debugを介して)で、ファイルがロードされ、解析されていることがわかります。ただし、変更を確認するには、タブを切り替える必要があります。asyncメソッドの読み込みが停止するとすぐにリストビューを更新するコードを変更するにはどうすればよいですか?