ボタンをクリックすると画面が作成され、各画面に新しいアクティビティがありますが、アクティビティの実行が遅すぎます (作成に 3 秒)。2 番目のアクティビティには、最初のアクティビティに依存する情報があるため、ボタンがクリックされる前にアクティビティを作成できません。次々と作成される4つの画面を持っていて、速度が速い他の方法はありますか?
package your.pack.namespace;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class ParsActivity extends Activity implements OnClickListener {
private Collection<String> title = new LinkedList<String>();
public Collection<String> desc = new LinkedList<String>();
public NodeList Items = getNodeList();
Collection<String> secTitle = new LinkedList<String>();
Document doc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setScrollContainer(true);
ll.setBackgroundResource(R.drawable.gradientbackground);
CreateScr(ll,Items);
}
private void CreateScr(LinearLayout l1,NodeList btns){
for(int i=0;i<btns.getLength();i++){
Element eElement= (Element)btns.item(i);
this.title.add(getTagValue("title",eElement));
this.desc.add(getTagValue("description",eElement));
}
btnCreate(title,l1);
this.setContentView(l1);
}
public void btnCreate (Collection<String> name,LinearLayout l1)
{
int k=0;
for(String i:name ){
Button btnNew = new Button(this);
btnNew.setId(k);
//btnNew.setBackgroundResource(R.drawable.bottomrow) ;
btnNew.setText(Html.fromHtml("<b>" + i + "</b>" + "<br />"));
l1.addView(btnNew);
k++;
btnNew.setOnClickListener(this);
}
this.setContentView(l1);
}
public static Document getDocument(String url)
throws MalformedURLException, IOException, Exception {
URL documentUrl = new URL(url);
URLConnection conn = documentUrl.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document;
InputStream stream = null;
try {
stream = conn.getInputStream();
document = builder.parse(stream);
} finally {
if (stream != null) stream.close();
}
return document;
}
public NodeList getNodeList (){
try {
doc = getDocument("http://afishadroid.about.od.ua/main.xml");
} catch (Exception ioe) {
//Обрабатываем ошибку
}
NodeList nd = doc.getElementsByTagName("item");
return nd;
}
public Element getElement (NodeList nl,int id1){
Element eElement = (Element)nl.item(id1);
return eElement;
}
protected static String getTagValue(String sTag, Element eElement) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(this, SecondActivity.class);
// intent.putExtra("ID",v.getId());
startActivity(intent);
//Intent intent = new Intent(this, SecondActivity.class) .putExtra("ID", v.getId()); startActivity(intent);
}
}