我是 Andoid 的新手,还在学习。
我正在尝试在包含三个文件的 TabHost 内的自定义列表视图中选择一个项目。一个用于 Tabhost,一个用于标准列表视图,一个用于修改后的列表视图。
下面添加的代码正确显示。我只是无法弄清楚如何长按显示列表中的项目,以便我可以将其从列表中删除。
第一个活动
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);
}
}
单独文件中的第二个活动。
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));
}
}
第三个文件中的第三个活动。
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;
}
}
}