탭을 눌러 리스트가 출력되게끔 하고싶은데
탭은 잘 나오지만 리스트가 출력이 안됩니다.
Logcat을 보니 getView()가 호출아 아예안되네요
어떻게해야하나요?
package com.test.tap.tap_test;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Tab_TestActivity extends TabActivity {
/** Called when the activity is first created. */
private TabHost tabHost = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec f_tabspec = tabHost.newTabSpec("tab1");
TabSpec s_tabspec = tabHost.newTabSpec("tab2");
TabSpec t_tabspec = tabHost.newTabSpec("tab3");
TabSpec fo_tabspec = tabHost.newTabSpec("tab4");
TabSpec fi_tabspec = tabHost.newTabSpec("tab5");
LayoutInflater vi1 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi2 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi3 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi4 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi5 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view1 = (View)vi1.inflate(R.layout.tabview, null);
View view2 = (View)vi2.inflate(R.layout.tabview, null);
View view3 = (View)vi3.inflate(R.layout.tabview, null);
View view4 = (View)vi4.inflate(R.layout.tabview, null);
View view5 = (View)vi5.inflate(R.layout.tabview, null);
LinearLayout layout1 = (LinearLayout)view1.findViewById(R.id.LinearLayout01);
LinearLayout layout2 = (LinearLayout)view2.findViewById(R.id.LinearLayout01);
LinearLayout layout3 = (LinearLayout)view3.findViewById(R.id.LinearLayout01);
LinearLayout layout4 = (LinearLayout)view4.findViewById(R.id.LinearLayout01);
LinearLayout layout5 = (LinearLayout)view5.findViewById(R.id.LinearLayout01);
layout1.setBackgroundResource(R.drawable.bgcolor);
layout2.setBackgroundResource(R.drawable.bgcolor);
layout3.setBackgroundResource(R.drawable.bgcolor);
layout4.setBackgroundResource(R.drawable.bgcolor);
layout5.setBackgroundResource(R.drawable.bgcolor);
TextView tv1 = (TextView)view1.findViewById(R.id.text);
TextView tv2 = (TextView)view2.findViewById(R.id.text);
TextView tv3 = (TextView)view3.findViewById(R.id.text);
TextView tv4 = (TextView)view4.findViewById(R.id.text);
TextView tv5 = (TextView)view5.findViewById(R.id.text);
//tabHost.getTabWidget().setDividerDrawable(R.drawable.white);
tv1.setText("마이코치");
tv1.setTextColor(Color.BLACK);
tv2.setText("식사\n다이어리");
tv2.setTextColor(Color.BLACK);
tv3.setText("건강\n다이어리");
tv3.setTextColor(Color.BLACK);
tv4.setText("추천\n프로그램");
tv4.setTextColor(Color.BLACK);
tv5.setText("설정");
tv5.setTextColor(Color.BLACK);
f_tabspec.setIndicator(view1);
f_tabspec.setContent(new Intent(this, Test_tab.class));
s_tabspec.setIndicator(view2);
s_tabspec.setContent(new Intent(this, Test_tab.class));
t_tabspec.setIndicator(view3);
t_tabspec.setContent(new Intent(this, Test_tab.class));
fo_tabspec.setIndicator(view4);
fo_tabspec.setContent(new Intent(this, Test_tab.class));
fi_tabspec.setIndicator(view5);
fi_tabspec.setContent(new Intent(this, Test_tab.class));
//Log.i("asdf", "test");
tabHost.addTab(f_tabspec);
tabHost.addTab(s_tabspec);
tabHost.addTab(t_tabspec);
tabHost.addTab(fo_tabspec);
tabHost.addTab(fi_tabspec);
tabHost.getTabWidget().setCurrentTab(0);
}
}
탭부분
package com.test.tap.tap_test;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.*;
import android.widget.*;
public class Test_tab extends ListActivity {
final ArrayList<ListInfo> liList = new ArrayList<ListInfo>();
Context ctx;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_tab);
ListInfo in;
in = new ListInfo("타이틀1", "내용1", R.drawable.icon);
liList.add(in);
in = new ListInfo("타이틀2", "내용2", R.drawable.icon);
liList.add(in);
in = new ListInfo("타이틀3", "내용3", R.drawable.icon);
liList.add(in);
ListInfoAdapter listinfoAdapter = new ListInfoAdapter(this, R.layout.listview_test, R.id.toptxt, liList);
setListAdapter(listinfoAdapter);
// TODO Auto-generated method stub
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(this, position, Toast.LENGTH_LONG);
}
private class ListInfoAdapter extends ArrayAdapter<ListInfo> {
private ArrayList<ListInfo> items;
private int rsrc;
public ListInfoAdapter(Context ctx, int rsrcId, int txtId, ArrayList<ListInfo> data){
super(ctx, rsrcId, txtId);
this.items = data;
this.rsrc = rsrcId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("asdf", "getview");
// TODO Auto-generated method stub
View v = convertView;
if(v == null) {
LayoutInflater li = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.listview_test, null);
}
ListInfo a = items.get(position);
if( a != null ) {
((TextView)v.findViewById(R.id.toptxt)).setText(a.getText1());
((TextView)v.findViewById(R.id.bottomtxt)).setText(a.getText2());
((ImageView)v.findViewById(R.id.imageview)).setImageResource(a.getImagersrc());
}
return v;
}
}
}
리스트부분
package com.test.tap.tap_test;
public class ListInfo {
private String text1;
private String text2;
private int imagersrc;
public ListInfo(String text1, String text2, int imagersrc){
this.text1 = text1;
this.text2 = text2;
this.imagersrc = imagersrc;
}
public String getText1(){
return this.text1;
}
public String getText2(){
return this.text2;
}
public int getImagersrc(){
return this.imagersrc;
}
}
데이터 부분




자답입니다.
public ListInfoAdapter(Context ctx, int rsrcId, int txtId, ArrayList<ListInfo> data){
super(ctx, rsrcId, txtId);
this.items = data;
this.rsrc = rsrcId;
}
이부분에서 super(ctx, rsrcId, data)로 바꾸니까 되네요~