Android two ListView - two OnItemClickListener - java

I have two ListView side by side in my activity and i want to only make it possible to select one item in one list at a time.
But right now if i select one item then one in the other list, the selections in both list are cleared, which is strange because when i check which listeners is called using logs everything seems to be working the way it should.
Also if i keep selecting different items at some point they start working like there was nothing in the listener because no list is cleared and i can select one item in each list. But i want to only be able to select one at a time so that's why i tried to reset the selection of the other ListView when you select an item in one of the two.
This code is at the end of the method where i initialize the ListViews.
selectedT1 and selectedT2 are initialized at -1
team1ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterV, View v, int position, long id) {
selectedPlayer = (String) adapterV.getItemAtPosition(position);
selectedT1 = position;
if(selectedT2 > -1){
team2ListView.clearChoices();
adapter2.notifyDataSetChanged();
selectedT2 = -1;
}
}
});
team2ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterV, View v, int position, long id) {
selectedPlayer = (String) adapterV.getItemAtPosition(position);
selectedT2 = position;
if(selectedT1 > -1){
team1ListView.clearChoices();
adapter1.notifyDataSetChanged();
selectedT1 = -1;
}
}
});
The xml of my listviews if it can help, they both are single choice and i have a button under them to validate the choice made but for that i need to be able to only select one of the items and not one in each list.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:id="#+id/team1ListView"
android:layout_height="200dp"
android:choiceMode="singleChoice"
android:listSelector="#666666"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight="0.5"
android:id="#+id/team2ListView"
android:choiceMode="singleChoice"
android:listSelector="#666666"/>
</LinearLayout>
Thanks for your time and help.

Related

Android animation and setBackroundResource conflict?

I have a GridView with items that change background resource when an item is clicked.
At the same time I want to animate a layouts position, when I do this however, the background resource for gridView item doesn't change the first time the animation is played
What i want to happen:
item is clicked
1. item backgroundResource is changed
2.a hidden layout is shown and animated
what actually seems to be happening is:
First time when the layout is still hidden the animation is shown but the background resource of the clicked item is not changed, any subsequent item clicks set the resource as it should and the animation works.
EDIT:
I've played around a little more and the issue seems to be the visibility "gone" rather than the animation, if i set the layout to Visibility="invisible" then the resource is applied, so it seems that if the gridView is moved in any kind of way (gridView is beneath the hidden layout that i wan't to show) the resource is ignored?
i.e.:
<LinearLayout
android:id="#+id/dateDetailContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"> //instead of gone
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a Placeholder for the chosen dates' items, it's gonna look super awesome once i implement this shit"
android:textSize="15sp"
/>
</LinearLayout>
this is the onItemClickListener:
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
scaleAnimateHeight(findViewById(R.id.dateDetailContainer));
setSelectedBackground(v, gridview);
}
scaleAnimateHeight():
private void scaleAnimateHeight(View v){
LinearLayout tv = (LinearLayout) v;
tv.setVisibility(View.VISIBLE);
Animation expand = AnimationUtils.loadAnimation(this, R.anim.from_left);
tv.startAnimation(expand);
}
setSelectedBackground():
private void setSelectedBackground(View v, GridView gridview ){
v.setBackgroundResource(R.drawable.back_selected);
}
anim.from_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="250"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>
and the layout:
<LinearLayout
android:id="#+id/dateDetailContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a Placeholder"
android:textSize="15sp"
/>
</LinearLayout>
Edit:
Instead of:
v.setBackgroundResource(R.drawable.back_selected);
try:
setImageDrawable(R.drawable.back_selected);
or
setImageDrawable(getResources().getDrawable(R.drawable.back_selected));
Try reversing your method calls within your listener. You are setting the resource after you change the visibility and run the animation, so it won't show until you click it the second time.
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//HERE
setSelectedBackground(v, gridview);
scaleAnimateHeight(findViewById(R.id.dateDetailContainer));
}

Can't select ListView items

I have a ListView that uses a custom adapter. Each element in the ListView contains a RadioButton and a TextView.
Here is my adapter, it takes an ArrayList of Employees (An object that currently only contains a name):
public class EmployeeAdapter extends ArrayAdapter<Employee> {
private ArrayList<Employee> listEmployees;
// Give the adapter the context and layout we are operating it, as well as a list of employees to put in the list.
public EmployeeAdapter(Context context, int layout, ArrayList<Employee> listEmployees) {
super(context, layout, listEmployees);
this.listEmployees = listEmployees;
}
// We override the basic getView function since our list is custom.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
// If there is nothing left to put in the view, inflate the view in the rowemployee layout.
if (v == null){
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.rowemployees, null);
}
Employee i = listEmployees.get(position);
// Check if there's still an employee in the list.
if (i != null){
TextView name = (TextView) v.findViewById(R.id.text_employeename);
name.setText(i.getName());
}
// Alternate row colors.
if (position % 2 == 0) {
v.setBackgroundColor(Color.parseColor("#FFFFFF"));
} else {
v.setBackgroundColor(Color.parseColor("#e5fff4"));
}
return v;
}
}
Here is the listview declaration in my XML layout:
<ListView android:id="#+id/employees_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="2dp"
android:paddingRight="1dp"
android:background="#drawable/borderlist"
android:choiceMode="singleChoice"
android:listSelector="#48ad82"
android:layout_below="#id/employees_header">
</ListView>
And here is the layout of every item of the ListView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_employee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:descendantFocusability="blocksDescendants">
<RadioButton android:id="#+id/radio_employee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"/>
<TextView
android:id="#+id/text_employeename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_toRightOf="#id/radio_employee"
android:layout_marginTop="3dp"
android:layout_marginLeft="5dp"
android:focusable="false" />
</RelativeLayout>
I input a bunch of Employee objects into an ArrayList, which I push to the adapter, and then I set a setOnItemClickListener on the list. The listener contains this code:
OnItemClickListener onItemClickListener_employee
= new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Toast.makeText(getApplicationContext(), String.valueOf(view.isSelected()) , Toast.LENGTH_SHORT).show();
}
};
view.isSelected() always returns false. Why? I've been trying to figure out how to select an element on a list containing something else than just a TextView for a couple of hours, and the SDK documentation isn't very helpful, this is getting old.
When I press on the list's items, it seems like the TextView or the RadioButton get pressed instead. Shouldn't focusable="false" prevent this ( Android custom ListView unable to click on items )?
To get the item chosen, add the following method to your adapter (untested code):
public Employee getItemAt(int position){
return listEmployees.get(position);
}
Then in your handler, pass the position to the new adapter method above
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Employee e = adapter.getItemAt(position); //or whatever your adapter instance is named
Toast.makeText(getApplicationContext(), e.getName(), Toast.LENGTH_SHORT).show();
}
Since the view is just for displaying data, you really don't care about the view itself (unless you want to remove it, hilight it, etc).

Android listview with multiple controls

I am new to android. I am developing an application in which there is a list view of students with edit and delete buttons. Like
STUDENT LIST
[ABC] [edit] [delete]
[DEF] [edit] [delete]
With this code im able to list student details in a <Textview>
public class DataBaseDemoActivity extends ListActivity {
/** Called when the activity is first created. */
SQLiteDatabase db;
Button btnInsert;
ArrayAdapter<String> students;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
db=openOrCreateDatabase("StudentDB",SQLiteDatabase.CREATE_IF_NECESSARY,null);
Cursor c=db.rawQuery("SELECT * FROM temp",null);
String[] students = new String[c.getCount()];
if (c.moveToFirst())
{
for (int i = 0; i < c.getCount(); i++)
{
students[i] = c.getString(0).toString()+" "+c.getString(1).toString();
c.moveToNext();
}
}
c.close();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, students));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}catch(SQLException e)
{
}
}
}
I need to store the id of the record with in the list view so that when i click on the edit or delete button, i'll have to find out the id and make changes on the DB. How can i set values to two fields say <TextView>[show details] and <EditText>[visibility: insisible - to save id of the record]. I am able to get the details to the <TextView> using the above code. Any suggestion will be appreciated.
UPDATE :
Layout i am using
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:inputType="text"
android:onClick="showInfo"
/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="230dip"
android:layout_height="wrap_content"
android:textSize="16sp"
android:id="#+id/studentInfo" >
</TextView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/action"
android:onClick="showInfo"
/>
</LinearLayout>
You can get the Id within cursor data fetch loop, use any HashMap<id,String> collection for it and store id along with data (text).
As per your requirement, I suggest you to use SimpleCursorAdapter instead of ArrayAdapter with ListView.
So you can manage easily your database records with your list and also get the all information related to database for particular record when List Item clicked.
Look at SimpleCursorAdapters and ListViews
Creating a custom CursorAdapter for Android
after this line..
students[i] = c.getString(0).toString()+" "+c.getString(1).toString();
student_ids[i]=Integer.parseInt(//get the id... )
//and you dont need to put it in invisible edittext...
in onclick method you will get integer "position"..and get tha value in students_ids[] at that position..
int id=students_ids[position];

Android - How to get all the childrens under the custom listview even if we perform scrolling

I have a custom listview adapter with a checkbox,imageview, textview. and i also have a button and a checkbox(for select all) in my main layout(not in listview).
What here i want is to check all these listview checkboxes at once when i check my main layout's checkbox.And I want to get that related textview id as dynamically.
i tried few techniques using getChaildAT(i).but it's not working with my code.with this i'm able to check/uncheck only particular visible group of checkboxes.While scroll down to list it get failed.
My aim is to check/uncheck all the checkboxes even with scroll and get the related id's.So Pls provide any other way to get all the children count in that custom list view.
In main activity I've custom adapter code like this
filterlist.setAdapter(new CustomAdptr(this));
class CustomAdptr extends ArrayAdapter {
Activity context;
String[] eventtypename;
CustomAdptr(Activity context) {
super(context, android.R.layout.simple_list_item_multiple_choice, filterListdata);
rowView.clear();
this.context = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View viewrow = convertView;
if (viewrow == null) {
LayoutInflater inflater = context.getLayoutInflater();
viewrow = inflater.inflate(R.layout.filterlistrow, null);
}
ImageView iw = (ImageView)viewrow.findViewById(R.id.img);
try {
String image = filterListdata.get(position).getFilterImg();
byte[] imbbyte = com.cincinnati.parks.Base64.decode(image);;
Bitmap bmp=BitmapFactory.decodeByteArray(imbbyte,0,imbbyte.length);
iw.setImageBitmap(bmp);
}catch (Exception e) {
e.printStackTrace();
}
TextView tv = (TextView)viewrow.findViewById(R.id.title);
tv.setText(filterListdata.get(position).getFilterImageName());
final CheckBox chkbx = (CheckBox)viewrow.findViewById(R.id.checkbox);
chkbx.setChecked(true);
TextView selectedid = (TextView)viewrow.findViewById(R.id.rid);
selectedid.setText(String.valueOf(filterListdata.get(position).getFilterImgId()));
rowView.add(viewrow);
viewrow.setClickable(true);
viewrow.setFocusable(true);
checkboxImagelist.clear();
for(int i=0;i<filterListdata.size();i++) {
checkboxImagelist.add(filterListdata.get(i).getFilterImgId());
}
chkbx.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (chkbx.isChecked()) {
FilterImageId.clear();
checkboxImagelistall.clear();
topOkbuttongray.setVisibility(4);
topOkbutton.setVisibility(0);
rb = (CheckBox) v;
FilterImageId.add(filterListdata.get(position).getFilterImgId());
checkboxImagelist.addAll(FilterImageId);
checkboxImagelistall.addAll(FilterImageId);
}else {
FilterImageId.clear();
FilterImageId.add(filterListdata.get(position).getFilterImgId());
checkboxImagelistall.remove(FilterImageId);
checkboxImagelist.removeAll(FilterImageId);
if((checkboxImagelist.size()) == 0){
topOkbuttongray.setVisibility(0);
topOkbutton.setVisibility(4);
}
if (filterListdata.size() != checkboxImagelist.size()) all.setChecked(false);
}
if (filterListdata.size() == heckboxImagelist.size()) all.setChecked(true);
}
});
return (viewrow);
}
}
The below code is for check all button
OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
int Id;
System.out.println("enter set all button");
rb = (CheckBox) v;
if(rb.isChecked()) {
System.out.println("enter set all button rb.isChecked()");
topOkbutton.setVisibility(0);
topOkbuttongray.setVisibility(4);
checkboxImagelistall.clear();
checkboxImagelist.clear();
//markAll(true);
for(int i=0;i<filterListdata.size();i++) {
Id = filterListdata.get(i).getFilterImgId();
checkboxImagelistall.add(Id);
checkboxImagelist.add(Id);
}
System.out.println("In enable condition filterlist.getChildCount()============="+filterlist.getChildCount());
System.out.println("In enable condition filterlist.getAdapter().getCount()============="+filterlist.getAdapter().getCount());
/*for(int i=0; i < filterlist.getAdapter().getCount(); i++){*/
for(int i=0; i < filterlist.getChildCount(); i++){
LinearLayout itemLayout = (LinearLayout)filterlist.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.checkbox);
//CheckBox cb = (CheckBox)filterlist.getAdapter().getView(i, null, null);
cb.setChecked(true);
TextView tv = (TextView)filterlist.getChildAt(i).findViewById(R.id.rid);
rowIdstr.add(tv.getText().toString());
}
}else {
System.out.println("enter set all button rb.isChecked() Not");
all.setChecked(false);
rb.setChecked(false);
topOkbutton.setVisibility(4);
topOkbuttongray.setVisibility(0);
System.out.println("In disable condition filterlist.getChildCount()============="+filterlist.getChildCount());
System.out.println("In disable condition filterlist.getAdapter().getCount()============="+filterlist.getAdapter().getCount());
//markAll(false);
for(int i=0; i < filterlist.getChildCount(); i++){
//CheckBox cb = (CheckBox)filterlist.getAdapter().getView(i, null, null);
LinearLayout itemLayout = (LinearLayout)filterlist.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.checkbox);
cb.setChecked(false);
rowIdstr.clear();
checkboxImagelistall.clear();
}
}
}
};
all.setOnClickListener(radio_listener);
And I used below .xml files for custom listing
for check all button in main layout I used this
<CheckBox android:id="#+id/radioselectall"
android:layout_width="30dp" android:layout_height="20dp"
android:layout_marginLeft="10dp" android:layout_marginTop="4dp"
android:layout_marginRight="10dp" android:checked="true" />
And the listview is
<ListView
android:id="#+id/listm"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp" />
</LinearLayout>
And another .xml file is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
>
<CheckBox
android:layout_width="40dp"
android:scaleType="centerCrop"
android:id="#+id/checkbox"
android:layout_height="40dp"
android:layout_marginTop="4dp"
android:checked="true"/>
<ImageView
android:id="#+id/img"
android:scaleType="centerCrop"
android:layout_marginLeft="30dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="left"/>
<TextView
android:layout_width="150dp"
android:scaleType="centerCrop"
android:id="#+id/title"
android:layout_height="fill_parent"
android:textStyle="normal"
android:layout_marginTop="2dp"
android:layout_marginLeft="30dp"
android:textColor="#color/white"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:id="#+id/rid"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16sp"
android:visibility="invisible"
/>
</LinearLayout>
There's no way to do that except storing the states in data underlying your adapter items, because there is actually finite number of recyclable items in a list view, it's significantly smaller than the possible number of data items.
So, my suggestion is either store an ArrayList of Booleans corresponding to the items in your filterListdata or add the booleans to the items stored in filterListdata. And then in getView() set checked state of the checkbox according to the boolean checked flag of the item.
This way, when you need to check all checkboxes in the ListView, you can run through all the items and set all checked flags to true, then call notifyDataSetChanged() to update visible items. And, of course, you'll have to set the checked flag in your OnClickListener for check box.
I'm not sure about what you mean by getting item ids though. Again, you can traverse your data array and for each item know whether it's checked or not.
Couple more comments:
Consider using OnCheckedChangeListener and the corresponding setter instead of OnClickListener for checkbox
Consider using only one listener instance for all checkboxes. Now you're creating a new one for each item. If the user ever wants to scroll your list fast, the app will have to create a massive load of useless new objects in the process, which will choke the GC (it'll have to constantly perform garbage collection) and the whole experience will be very chunky.
Use ViewHolder pattern to avoid creating bitmaps each time a new item needs to be displayed. This, too, can be a dramatic performance bottleneck.
After marking all checkboxes as true/false, call invalidate(); on list. This will refresh all the elements (visible or non-visible) in the list with latest properties set.
Try out.

ListView with a ListView header

I have a problem with adding a listview as a header in my listview (go go redundancy). The code is working, however only the first item shows up in the header. The body looks fine.
listView = (ListView) findViewById(R.id.default_list_view);
header = (ListView) getLayoutInflater().inflate(R.layout.savings_overview_header_list, null, false);
HeaderAdapter hAdapter = new HeaderAdapter(getLayoutInflater());
hAdapter.addItem("1");
hAdapter.addItem("2");
hAdapter.addItem("3");
header.setAdapter(hAdapter);
for (Policy p : saving.getPolicies()) {
adapter.addItem(p);
}
listView.addHeaderView(header);
listView.setAdapter(adapter);
headerView:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/default_list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="#drawable/list_divider"
android:dividerHeight="2px"
android:fadingEdge="none"
android:fitsSystemWindows="true"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:listSelector="#drawable/list_item_background_selected"
>
</ListView>
I have tried wrapping the ListView in a vertical LinearLayout but no cigar there either :(
hAdapter
private static class HeaderAdapter extends BaseAdapter {
private final LayoutInflater inflater;
protected ArrayList<String> data = new ArrayList<String>();
public HeaderAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
public void addItem(String s) {
data.add(s);
}
public View getView(int position, View convertView, ViewGroup parent) {
final PolicyViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.savings_overview_header_item, parent, false);
holder = new PolicyViewHolder();
holder.header = (TextView) convertView.findViewById(R.id.list_item_header);
holder.subHeader = (TextView) convertView.findViewById(R.id.list_item_subheader);
holder.img = (ImageView) convertView.findViewById(R.id.list_item_img);
convertView.setTag(holder);
} else {
holder = (PolicyViewHolder) convertView.getTag();
}
String s = data.get(position);
holder.header.setText(s);
holder.subHeader.setText(s);
holder.img.setImageResId(R.drawable.test);
return convertView;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return data.get(position);
}
public long getItemId(int position) {
return position;
}
private static class PolicyViewHolder {
TextView header;
TextView subHeader;
ImageView img;
}
}
header_item
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="#+id/list_item_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/list_item_value"
android:layout_toRightOf="#+id/header_image"
android:orientation="vertical" >
<TextView
android:id="#+id/list_item_header"
style="#style/header_list_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/list_item_subheader"
style="#style/list_header_sub_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="sub header" />
</LinearLayout>
</RelativeLayout>
i have tried to wrap a linearlayout="vertical" around this one as well
You have to tell the parent view how to stack your elememnts. This is necessary for parents like a LinearLayout. If you're going to have such an adapter, you need to have a parent to contain these things, UNLESS its a single view.
Update
Whenever you want to do processing with the views in a ListView you
need to create a custom adapter that will handle your logic
implementation and pass that information to the views as necessary.
A custom adater would inflate the views piece by piece, this can be
dynamic of fixed.
I suspect that your problem relates to Android simply not knowing how to handle the two levels of "scrollability" this design implies. Think about it - If the user drags over the header, how is Android supposed to know whether they mean to scroll the outer list or the list within the header? I once recall Romain Guy making the same point about placing ListViews inside ScrollViews, it's slightly meaningless.
What's probably happening is that Android makes the header big enough to simply display a single header list item and it assumes any dragging gesture by the user should apply to the outer list.
Generally, I think what you've described sounds like a bad design choice and you need to take a step back.
What functionally do you want this UI to do?
If it's simply that you want to display two sets of content within a single list, then this is a problem you need to solve within the ListAdapter implementation you're using. e.g. Take a look Jeff Sharkey's blog post on his SeparatedListAdapter.
Make a LinearLayout with vertical orientation and add both ListViews there. That should fix your hiccup.
Cheers.

Categories

Resources