Hello everyone and thank you for reading my question!
I'm currently developing an android app that has the following hierarchy:
One FragmentActivity is divided by three ListFragments.
One of these ListFragments uses a custom ArrayAdapter to display a List<> with a xml template on a ListView
This List<> is filled with dataset which are given id's. Datasets with id's lower than 10 are flagged "important", the other ones are flagged "not so important"
This is what I am looking for: I have two layout templates, and I want to display the "important" datasets with one layout and the "not so important" with the other layout.
I have searched for quite a while now, but it looks like noone has asked a question like this before.
I tried to use a second ListView and apply a second custom ArrayAdapter on it, but unfortunately, there is a restriction: Since I'm using ListFragment, I'm forced to use findViewById like this.
ListView list;
list = (ListView) rootView.findViewById(android.R.id.list);
When I tried to write the second custom ArrayAdapter, it showed an error here:
ListView list;
list_flat = (ListView) rootView.findViewById(android.R.id.list_flat);
Here is the entire ListFragment
public class LeaguePage extends ListFragment{
Global global_var;
ListView list, list_flat;
List <League> leagues = null;
ListAdapter adapter = null;
View rootView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.league_page, container, false);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
list_flat = (ListView) rootView.findViewById(android.R.id.list_flat);
try {
leagues = Leagues_Parser.parse(getActivity().getAssets().open("league_raw.xml"));
} catch (IOException e) {
e.printStackTrace();
}
adapter = new LeagueAdapter (getActivity(), R.layout.list_row, leagues);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Global.selectedTeam = Integer.valueOf(leagues.get(arg2).getInternalID());
Global.mViewPager.setCurrentItem(1, true);
}
});
}
}
This is the xml file I pass on to my ArrayAdapter
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/liga_flat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:paddingBottom ="10dip"
android:textColor="#040404"
android:textSize="25sp"
android:textStyle="normal"
android:typeface="serif" />
</RelativeLayout>
This is the xml layout file for the ListFragment
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main_Activity$search_page" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main_Activity$search_page" >
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="0dp"
android:divider="@null">
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Main_Activity$search_page" >
<ListView
android:id="@+id/android:list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp" >
</ListView>
</RelativeLayout>
</RelativeLayout>