im having an issue when i try to make a linearlayout with multiple listviews. originally when i added multiple custom linearlayouts containing a textview and a listview i could not scroll down the page so i found out adding a scrollview would fix this, which it did but for some reason it then cropped the linearlayout view so i could only see the top part of each list.
heres the code for the different parts:
Main layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/whatsNewTitle"
android:text="Whats New?"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30dip">
</TextView>
<Button android:layout_height="wrap_content"
android:id="@+id/home"
android:text="Home"
android:layout_weight="0.07"
android:layout_width="126dp">
</Button>
<ScrollView
android:id="@+id/sv1"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="630dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="@+id/whats_new_content"
android:layout_height="fill_parent">
</LinearLayout>
</ScrollView>
</LinearLayout>
layout im inflating and adding multiple times into main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/new_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:textSize="25dip">
</TextView>
<ListView
android:id="@+id/new_files"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#000000">
</ListView>
</LinearLayout>
the main activity that creates the multiple listviews and displays them:
public class WhatsNew extends Activity{
private Button homeBtn;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.whats_new_main);
CreateLastModDateList();
homeBtn = (Button) findViewById(R.id.home);
homeBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v){
Intent myIntent = new Intent(getApplication().getApplicationContext(),
Main.class);
startActivityForResult(myIntent, 0);
}
});
}
private ArrayList<File> GenerateNewFileDates(){
Files.clearFilesList();
Files.buildFilesList(Files.getRoot());
return Files.getAllFiles();
}
private void CreateLastModDateList(){
ArrayList<File> files = GenerateNewFileDates();
ArrayList<String> allDates = new ArrayList<String>();
ArrayList<String> dates = new ArrayList<String>();
Context c = this.getApplicationContext();
LinearLayout l = (LinearLayout) findViewById(R.id.whats_new_content);
/** Builds a list of all file dates **/
for(File file : files){
Date lastModifiedDate = new Date(file.lastModified());
allDates.add(lastModifiedDate.toString());
}
/** For each date, check if we have already put that date into the dates array
if we have then we want to ignore it, otherwise add it to the dates array. **/
for(String date : allDates){
if (exists(dates,date) == false){
dates.add(date);
}
}
for(String date : dates){
ArrayList<String> test = new ArrayList<String>();
test = generateFileList(date, files);
WhatsNewLayout whatsNew = new WhatsNewLayout(c,test, date);
l.addView(whatsNew);
}
}
public ArrayList<String> generateFileList(String date, ArrayList<File> mFiles){
ArrayList<String> filesFromDate = new ArrayList<String>();
for(File file : mFiles){
Date lastModifiedDate = new Date(file.lastModified());
boolean x = lastModifiedDate.toString().equals(date);
if (x == true){
filesFromDate.add(file.getName());
}
}
return filesFromDate;
}
public boolean exists(ArrayList<String> list, String compare){
boolean result = false;
if(list.contains(compare)){
result = true;
}
return result;
}
}
The custom linearlayout i inflate:
public class WhatsNewLayout extends LinearLayout {
private LayoutInflater mInflater;
public WhatsNewLayout(Context context, ArrayList<String> files, String date) {
super(context);
mInflater = LayoutInflater.from(context);
View convertView = new View(context);
/** initialize variables **/
DataHolder holder;
Context c = this.getContext();
ArrayAdapter<String> list = new ArrayAdapter<String>(c,
android.R.layout.simple_list_item_1, files);
convertView = mInflater.inflate(R.layout.whats_new_item, null);
holder = new DataHolder();
holder.modDate = (TextView) convertView.findViewById(R.id.new_date);
holder.FileList = (ListView) convertView.findViewById(R.id.new_files);
convertView.setTag(holder);
holder.modDate.setText(date);
holder.FileList.setAdapter(list);
this.addView(convertView);
}
}
Sorry about the large mass of code, but i didnt want to leave any details out in case it is important, hopefully this is everything, im sure its something really fundermental with my call of the layout but i just cannot see what is casuing the custom layout to be cut.
if any more details are required please let me know. =)