我的列表活动中的布局有些问题。我的列表包含分隔符和文本行
SetupActivity 扩展 ListActivity
private MyCustomAdapter mAdapter;
TextView selection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mAdapter = new MyCustomAdapter();
mAdapter.addItem("Help/FAQ");
mAdapter.addSeparatorItem("Connection to Server");
// mAdapter.addItem("Connection");
// mAdapter.addItem("Network");
// mAdapter.addItem("config");
// mAdapter.addItem("User");
// mAdapter.addItem("pass");
// mAdapter.addItem("Email");
// mAdapter.addItem("PlatForm");
mAdapter.addSeparatorItem("Consumption");
// mAdapter.addItem("100%");
mAdapter.addSeparatorItem("Map");
// mAdapter.addItem("Map rotation");
// mAdapter.addItem("auto Zoom");
// mAdapter.addItem("Measure Units");
// mAdapter.addItem("Show Heading");
// mAdapter.addItem("Compass North");*/
mAdapter.addFooterItem(getString(R.string.setup_note_map));
mAdapter.addSeparatorItem("Support");
mAdapter.addItem("About");
/*
* mAdapter.addItem("Contact Us"); mAdapter.addItem("Tutorial");
* mAdapter.addItem("Setup Wizard");
*/
mAdapter.addSeparatorItem("Blogs");
mAdapter.addFooterItem(getString(R.string.setup_note_blogs));
setListAdapter(mAdapter);
// selection = (TextView) findViewById(R.id.text);
}
public void onListItemClick(ListView parent, View view, int position,
long id) {
parent.getChildAt(position).setBackgroundColor(position);
if (position == 0) {
Intent myIntent = new Intent(SetupActivity.this,
WebviewHandlerActivity.class);
myIntent.putExtra("ressource", "help");
SetupActivity.this.startActivity(myIntent);
} else if (position == 6) {
Intent myIntent = new Intent(SetupActivity.this,
AboutActivity.class);
SetupActivity.this.startActivity(myIntent);
}
}
// Adapter Class
private class MyCustomAdapter extends BaseAdapter {
private static final int TYPE_ITEM = 2;
private static final int TYPE_SEPARATOR = 0;
private static final int TYPE_FOOTER = 1;
private static final int TYPE_MAX_COUNT = TYPE_ITEM + 1;
private ArrayList<String> mData = new ArrayList<String>();
private LayoutInflater mInflater;
private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();
private TreeSet<Integer> mFooterSet = new TreeSet<Integer>();
public MyCustomAdapter() {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(final String item) {
mData.add(item);
notifyDataSetChanged();
}
public void addSeparatorItem(final String item) {
mData.add(item);
// save separator position
mSeparatorsSet.add(mData.size() - 1);
notifyDataSetChanged();
}
public void addFooterItem(final String item) {
mData.add(item);
// save separator position
mFooterSet.add(mData.size() - 1);
notifyDataSetChanged();
}
@Override
public int getItemViewType(int position) {
if (mSeparatorsSet.contains(position))
return TYPE_SEPARATOR;
else if (mFooterSet.contains(position))
return TYPE_FOOTER;
return TYPE_ITEM;
}
@Override
public int getViewTypeCount() {
return TYPE_MAX_COUNT;
}
public int getCount() {
return mData.size();
}
public String getItem(int position) {
return mData.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.item1, null);
holder.textView = (TextView) convertView
.findViewById(R.id.text);
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.item2, null);
holder.textView = (TextView) convertView
.findViewById(R.id.textSeparator);
break;
case TYPE_FOOTER:
convertView = mInflater.inflate(R.layout.footer, null);
holder.textView = (TextView) convertView
.findViewById(R.id.note);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mData.get(position));
return convertView;
}
}
public static class ViewHolder {
public TextView textView;
}
我的 xmlitem1 & item2
包含一个LinearLayout
内部TextView
和我footer.xml
唯一的一个textView
我的问题是,当我点击一行时,它不会变成橙色来表示我点击了它,除了我的页脚......(我不想要的那个)
所以我发现这是因为它不在 aLinearLayout
所以我试图推迟LinearLayout
ofitem1.xml
但我不能再编译了。
有人可以向我解释如何通过单击动画而不是在我的页脚上来获取我的行吗?
干杯