게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
안드로이드) 탭뷰 내에 리스트뷰를 삽입했는데 에러가 납니다.
게시물ID : programmer_7688짧은주소 복사하기
작성자 : 서퐅
추천 : 0
조회수 : 2760회
댓글수 : 8개
등록시간 : 2015/01/18 22:29:09
정확히는 리스트뷰 삽입까지는 성공했으나,
 
리스트 아이템을 클릭했을 때 SingleItemView라는 새로운 레이아웃이 열리게 했는데 여기서 에러가 생기더라구요.
 
제가 탭뷰 프로젝트 따로 구성하고 리스트뷰 프로젝트 따로 구성했었는데,
 
리스트뷰 프로젝트만 따로 만들었을 땐 SingleItemView 출력까지 잘 됬었습니다.
 
그런데 탭뷰 프로젝트 속에 결합시키니까 여기서부터 안되네요 ㅠㅠ
 
JsoupListView.class에서 Listviewadapter를 부르고, Listviewadapter에서 listview_item 클릭 시 SingleitemView 클래스를 부르게 만들었습니다.
 
작은 조언이라도 부탁드립니다.
 
----------ㅡMain_activity.java----------------------------------------------------

package com.example.tabviewtest;
 

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.os.AsyncTask;
import android.os.Bundle;     
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ListView;
import android.widget.TabHost;
import android.annotation.SuppressLint;
import android.app.*;

@SuppressWarnings("deprecation")
public class Main_Activity extends TabActivity {
 
 TabHost mTab;
 WebView mWebView_munhwa;
 WebView mWebView_search;
 WebView mWebView_seat;
 ListView listview;
 ListViewAdapter adapter;
 ProgressDialog mProgressDialog;
 ArrayList<HashMap<String, String>> arraylist;
 static String NUM = "num";
 static String TITLE = "title";
 static String DATE = "date";
 // URL Address
 String url = "http://lib.nyj.go.kr/toegyewon/notice/notice.jsp";
 @SuppressLint("SetJavaScriptEnabled")
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //탭호스트 객체 생성
  TabHost mTab = getTabHost();
  //탭스팩 변수 선언
  TabHost.TabSpec spec;
  //custom레이아웃은 setcontentview 불가능 -> layoutinflater로 객체생성
//  LayoutInflater inflater = LayoutInflater.from(this);
 // inflater.inflate(R.layout.layout_main, mTab.getTabContentView(), true);
  LayoutInflater.from(this).inflate(R.layout.layout_main,
    mTab.getTabContentView(), true);

  spec = mTab.newTabSpec("tab1").setIndicator("메인")
    .setContent(R.id.tab_layout1);
  mTab.addTab(spec);
  spec = mTab.newTabSpec("tab2").setIndicator("도서 검색")
    .setContent(R.id.tab_layout2);
  mTab.addTab(spec);
  spec = mTab.newTabSpec("tab#").setIndicator("좌석 현황")
    .setContent(R.id.tab_layout3);
  mTab.addTab(spec);
  spec = mTab.newTabSpec("tab#").setIndicator("문화 행사")
    .setContent(R.id.tab_layout4);
  // Execute DownloadJSON AsyncTask
  new JsoupListView().execute();
  mTab.addTab(spec);
  
  mWebView_search= (WebView) findViewById(R.id.webview_search);
  mWebView_search.loadUrl("http://lib.nyj.go.kr:8080/kolas3_01/BookStand/search_simple.do?manage_code=MB");
  mWebView_search.getSettings().setJavaScriptEnabled(true);
  mWebView_search.setWebViewClient(new BlogWebViewClient());
  
 
  mWebView_seat= (WebView) findViewById(R.id.webview_seat);
  mWebView_seat.loadUrl("http://119.193.246.131/");
  mWebView_seat.getSettings().setJavaScriptEnabled(true);
  mWebView_seat.setWebViewClient(new BlogWebViewClient());
  mWebView_seat.getSettings().setBuiltInZoomControls(true);
//  mWebView_seat.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
  mWebView_seat.getSettings().setLoadWithOverviewMode(true);
  mWebView_seat.getSettings().setUseWideViewPort(true);
    
 
 
 }
 
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main_, menu);
  return true;
 }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event){
  if((keyCode == KeyEvent.KEYCODE_BACK) && mWebView_search.canGoBack()){
   mWebView_search.goBack();
   return true;
   
  }
  return super.onKeyDown(keyCode, event);
  
 }
 
 private class BlogWebViewClient extends WebViewClient{
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url){
   view.loadUrl(url);
   return true;
  }
 }
 
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
 // Title AsyncTask
 private class JsoupListView extends AsyncTask<Void, Void, Void> {
  @Override
  protected void onPreExecute() {
   super.onPreExecute();
   // Create a progressdialog
   mProgressDialog = new ProgressDialog(Main_Activity.this);
   // Set progressdialog title
   mProgressDialog.setTitle("공지사항");
   // Set progressdialog message
   mProgressDialog.setMessage("Loading...");
   mProgressDialog.setIndeterminate(false);
   // Show progressdialog
   mProgressDialog.show();
  }
  @Override
  protected Void doInBackground(Void... params) {
   // Create an array
   arraylist = new ArrayList<HashMap<String, String>>();
   try {
    // Connect to the Website URL
    Document doc = Jsoup.connect(url).get();
    // Identify Table Class "worldpopulation"
    
    Elements table = doc.select("table[class=boardlist_type1]");
    Elements tbody = table.select("tbody"); 
     // Identify all the table row's(tr)
     for (Element row : tbody.select("tr")) {
      HashMap<String, String> map = new HashMap<String, String>();
      
      // Identify all the table cell's(td)
      Elements tds = row.select("td");
      
      // Retrive Jsoup Elements
      // Get the first td
      map.put("num", tds.get(0).text());
      // Get the second td
      map.put("title", tds.get(1).text());
      // Get the third td
      map.put("date", tds.get(3).text());
      // Set all extracted Jsoup Elements into the array
      arraylist.add(map);
     }
    
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   return null;
  }
  @Override
  protected void onPostExecute(Void result) {
   // Locate the listview in listview_main.xml
   listview = (ListView) findViewById(R.id.listview);
   // Pass the results into ListViewAdapter.java
   adapter = new ListViewAdapter(Main_Activity.this, arraylist);
   // Set the adapter to the ListView
   listview.setAdapter(adapter);
   // Close the progressdialog
   mProgressDialog.dismiss();
  }
 }
 
}
--------------listviewadpater.java-----------------------------------------------------
package com.example.tabviewtest;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ListViewAdapter extends BaseAdapter {
 // Declare Variables
 Context context;
 LayoutInflater inflater;
 ArrayList<HashMap<String, String>> data;
// ImageLoader imageLoader;
 HashMap<String, String> resultp = new HashMap<String, String>();
 public ListViewAdapter(Context context,
   ArrayList<HashMap<String, String>> arraylist) {
  this.context = context;
  data = arraylist;
//  imageLoader = new ImageLoader(context);
 }
 @Override
 public int getCount() {
  return data.size();
 }
 @Override
 public Object getItem(int position) {
  return null;
 }
 @Override
 public long getItemId(int position) {
  return 0;
 }
 public View getView(final int position, View convertView, ViewGroup parent) {
  // Declare Variables
  TextView num;
  TextView title;
  TextView date;
  inflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View itemView = inflater.inflate(R.layout.listview_item, parent, false);
  // Get the position
  resultp = data.get(position);
  // Locate the TextViews in listview_item.xml
  num = (TextView) itemView.findViewById(R.id.num);
  title = (TextView) itemView.findViewById(R.id.title);
  date = (TextView) itemView.findViewById(R.id.date);
  // Capture position and set results to the TextViews
  num.setText(resultp.get(Main_Activity.NUM));
  title.setText(resultp.get(Main_Activity.TITLE));
  date.setText(resultp.get(Main_Activity.DATE));
  // Capture ListView item click
  itemView.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View arg0) {
    // Get the position
    resultp = data.get(position);
    Intent intent = new Intent(context, SingleItemView.class);
    // Pass all data rank
    intent.putExtra("num", resultp.get(Main_Activity.NUM));
    // Pass all data country
    intent.putExtra("title", resultp.get(Main_Activity.TITLE));
    // Pass all data population
    intent.putExtra("date",resultp.get(Main_Activity.DATE));
    // Start SingleItemView Class
    context.startActivity(intent);
   }
  });
  return itemView;
 }
}
--------------------singleitemview.java-----------------------------------
package com.example.tabviewtest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SingleItemView extends Activity {
 // Declare Variables
 String num;
 String title;
 String date;
 String position;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // Get the view from singleitemview.xml
  setContentView(R.layout.singleitemview);
  Intent i = getIntent();
  // Get the result of rank
  num = i.getStringExtra("num");
  // Get the result of country
  title = i.getStringExtra("title");
  // Get the result of population
  date = i.getStringExtra("date");
  // Locate the TextViews in singleitemview.xml
  TextView txtnum = (TextView) findViewById(R.id.num);
  TextView txttitle = (TextView) findViewById(R.id.title);
  TextView txtdate = (TextView) findViewById(R.id.date);

  // Set results to the TextViews
  txtnum.setText(num);
  txttitle.setText(title);
  txtdate.setText(date);
  // Capture position and set results to the ImageView
 }
}
 
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호