안드로이드 개발 질문/답변
(글 수 45,052)
public class MainActivity extends Activity {
public static String s;
public static TextView tv;
private HTMLParsingTask async;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String yourUrl = "http://www.google.com";
async = new HTMLParsingTask();
async.execute(yourUrl);
//tv = (TextView)findViewById(R.id.txtt);
//tv.setText(s);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
class HTMLParsingTask extends AsyncTask<String, Void, String>
{
Source source;
@Override
protected String doInBackground(String... params)
{
// TODO Auto-generated method stub
ArrayList<String> temp = new ArrayList<String>();
URL sUrl;
try
{
sUrl = new URL("params[0]);
InputStream is;
is = sUrl.openStream();
source = new Source(new InputStreamReader(is, "EUC-KR"));
source.fullSequentialParse();
List<Element> tags = source.getAllElements(HTMLElementName.TD);
for (int i = 0; i < tags.size(); i++) {
Element e = (Element) tags.get(i);
String Find = null;
Find = e.getContent().getTextExtractor().toString().trim();
temp.add(Find);
//Log.d("al값", ""+temp.get(i));
}
}
catch (MalformedURLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp.toString();
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
MainActivity.tv.setText(result);
super.onPostExecute(result);
}
}
html 코드 긁어오는데 까지는 성공했습니다
근데 이 코드를 onPostExecute에서 뿌릴려니 findViewById가 안 먹히고
어쩔수 없이 TextView를 static으로 선언해서 썼는데 result 값이 들어가지 않습니다
무엇이 잘못된 건가요 ㅠㅠㅠㅠ
고수님들 답변부탁드리겠습니다(__)
아
안드로이드 순차적으로 디버깅 확인하는 방법도 같이 가르쳐주시면 감사하겠습니다
async가 외부 클래스로 선언이 되어있네요
하나의 파일안에만 들어있을뿐 서로 다른 클래스 입니다.