私はAndoidを初めて使用し、まだ学習しています。
3つのファイルがあるTabHost内のカスタムリストビューでアイテムを選択しようとしています。1つはタブホスト用、もう1つは標準リストビュー用、もう1つは変更されたリストビュー用です。
以下に追加されたコードは正しく表示されます。表示されたリストのアイテムを長押しする方法がわからないので、リストから削除できます。
最初のアクティビティ
public class View_categories extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_edit_cat);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Category").setContent(new Intent(this, Category.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Sub_Category").setContent(new Intent(this, Sub_category.class)));
tabHost.setCurrentTab(0);
}
}
別のファイルの2番目のアクティビティ。
public class Category extends ListActivity {
List<String> cCategory;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
catList(); //Loads list
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,cCategory));
}
}
3番目のファイルの3番目のアクティビティ。
public class Sub_category extends ListActivity {
List<String> sSub_cat;
List<String> sCategory;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
subList(); //loads list
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,R.id.textView1,sCategory));
}
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
List<String> objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.sub_cat_list, parent, false);
TextView cat_v = (TextView) row.findViewById(R.id.textView1);
TextView sub_v = (TextView) row.findViewById(R.id.textView2);
cat_v.setText(sCategory.get(position));
sub_v.setText(sSub_cat.get(position));
return row;
}
}
}