I’m doing something quite similar to the tutorial http://www.vogella.com/articles/AndroidListView/article.html#listadvanced_interactive.
I now want to put a button at the bottom. Then click the button and do something with the selected Values.
I understand, that I need some new layout, because adding the button to the existing one would just add a button to every textview. But I cant figure out how to do it.
Some help would be very nice. Thanks in advance. 🙂
Edit: That’s my layout at the moment.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="30px" >
</TextView>
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="4px"
android:layout_marginRight="10px" >
</CheckBox>
</RelativeLayout>
This creates something that looks like this:
https://i.stack.imgur.com/cN8Dl.png
My adapter looks like this:
public class AttributeAdapter extends ArrayAdapter<Attribute> {
private final List<Attribute> list;
private final Activity context;
public AttributeAdapter(Activity context, List<Attribute> list) {
super(context, R.layout.activity_select_attributes, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.activity_select_attributes, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Attribute element = (Attribute) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName() + " " + list.get(position).getType());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
Now i want a button at the bottom to continue with the selected values.
Create a new layout or xml file named
activity_baseand add following:in your
ListActivityin theOncreateaddsetContentView(R.layout.activity_base);This should do the job.