파싱한 후에 버튼 클릭하면 해당 값 넘겨주는 버튼 이벤트처리를 해야하는데,
어떻게 해야할지 모르겠어요ㅠㅠ
xml 에 android:onClick 을 써서 우선 클릭이 되게끔은 했는데, 값을 어떻게 넘겨줄지 모르겠어요ㅠ
package com.cproject;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.content.Context;
import android.content.Intent;
import android.widget.*;
public class search_res extends Activity{
ArrayList<HashMap<String, String>> data;
ListView list;
TextView title, writer, company, position, position2;
Button but;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent i = getIntent();
String search = i.getExtras().getString("search").toString();
TextView kwd = (TextView) findViewById(R.id.search);
setContentView(R.layout.search_list1);
if(search.length()<1)
{
Toast.makeText(getApplicationContext(), "도서명, 저자 또는 출판사를 입력해주세요.", Toast.LENGTH_SHORT).show();
}else{
data = new ArrayList<HashMap<String, String>>();
try {
builPostList(search);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
list = (ListView) findViewById(R.id.listView1);
SimpleAdapter sa = new SimpleAdapter(this, data, R.layout.search_list2, new String[] {"title", "writer", "company", "position", "but"}, new int[]{R.id.title, R.id.writer, R.id.company, R.id.position, R.id.bt1});
list.setAdapter(sa);
}
}
private void builPostList(String search) throws MalformedURLException, IOException
{
String surl = "http://library.skhu.ac.kr/DLiWeb20/components/searchir/result.aspx?m_var=421&srv_id=31&qy_frm=QUICK&adf=&adt=&cl_id=ALL&rid_all=&st_f=&st_o=&pg=1&rpp=20&mc=300&dp_op=LIST&t_path=&qy_typ=KEYWORD&brch=ALL&qy_idx=TITL&qy_kwd="
+ URLEncoder.encode(search, "UTF-8");
String nurl = null;
try{
URL url = new URL("surl);
data.clear();
InputStream html = url.openStream();
Source source = new Source(new InputStreamReader(html,"UTF-8"));
source.fullSequentialParse();
Element table = (Element) source.getAllElements(HTMLElementName.TABLE).get(28);
List<Element> trtag = table.getAllElements(HTMLElementName.TR);
for(int i=1; i<trtag.size(); i+=2)
{
Element tr = (Element) trtag.get(i);
if (tr.getAllElements(HTMLElementName.TD).size() < 2)
continue;
Element td = (Element) tr.getAllElements(HTMLElementName.TD).get(1);
List<Element> sp = td.getAllElements(HTMLElementName.SPAN);
HashMap<String, String> hm = new HashMap<String, String>();
for(Iterator it = sp.iterator(); it.hasNext();)
{
Element le = (Element) it.next();
String c = le.getAttributeValue("class");
String t = le.getAttributeValue("title");
String v = le.getContent().toString();//le.getAttributeValue("value");
if(v == null)
{
continue;
}
if(c != null && c.equals("result_title"))
{
String value = le.getContent().toString();//le.getAttributeValue("value").toString();
TextView tv = new TextView(this);
tv.setText(Html.fromHtml(value));
hm.put("title", "도서명 : " + tv.getText().toString());
}
if (t == null)
continue;
if(t.equals("저자"))
{
String value = le.getContent().toString();//le.getAttributeValue("value").toString();
hm.put("writer", "저자 : " + value);
}
if(t.equals("출판사"))
{
String value = le.getContent().toString();//le.getAttributeValue("value").toString();
hm.put("company", "출판사 : " + value);
}
if (tr.getAllElements(HTMLElementName.A).size() < 3)
continue;
Element po = (Element) td.getAllElements(HTMLElementName.A).get(2);
hm.put("position",(po.getContent().toString())); //넘겨주고 싶은 값
hm.put("but", "위치보기"); //버튼
}
data.add(hm);
}
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}
}
public void pClick (View v)
{
Intent i = new Intent(search_res.this, position1.class);
startActivity(i);
}
}
우선 이렇게 했는데, 다른 방법이 있나요???!