I have a function from where I display a layout dynamically. It shows an event created for a day. It has a start time and end time as a parameter. For testing purpose I had use array of a float with some values . But now I want to add the start time and end time values to this function which I am getting from another activity. I want them to use in an array dynamically and use it in a function.
Following is my function :
private void createEvent(LayoutInflater inflater, ViewGroup dayplanView,float startTime, float endTime) {
View eventView = inflater.inflate(R.layout.event_view, dayplanView, false);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) eventView.getLayoutParams();
float margin = (startTime * 60);
float distance = (endTime - startTime);
float height = (distance * 60);
int result = ((int)margin);
int result1 = ((int)height);
layoutParams.topMargin = dpToPixels(result+10);
layoutParams.height = dpToPixels(result1);
eventView.setLayoutParams(layoutParams);
dayplanView.addView(eventView);
}
I am calling it onCreate view :
ViewGroup dayplanView = (ViewGroup)view.findViewById(R.id.hoursRelativeLayout);
float[] startTimes = new float[] {2.5f,8f,4f,11f,5f,8.5f,12.3f,15.3f,21f,1f};
float[] endTimes = new float[] {3f,9f,7f,12.5f,7.5f,11f,1.5f,16f,22f,2f};
for(int i = 0; i < s.size(); i++) {
createEvent(inflater, dayplanView, startTimes[i], endTimes[i]);
}
I am getting from minutes and to minutes onActivity result and this I ant to use in an array and in function :
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==1) {
fromMinutes = data.getIntExtra("fromMinute",0);
toMinutes = data.getIntExtra("toMinute",0);
}
}
Please help..
Edit :
ArrayList<Integer> s = new ArrayList<Integer>();
s.add(fromMinutes);
ArrayList<Integer> e = new ArrayList<Integer>();
e.add(toMinutes);
for(int i = 0; i < s.size(); i++) {
createEvent(inflater, dayplanView,s[i], e[i]);
}
I am getting error on s[i] as array type expected found java.util.array list.
private void createEvent(LayoutInflater inflater, ViewGroup dayplanView,int fromMinutes, int toMinutes) {
View eventView = inflater.inflate(R.layout.event_view, dayplanView, false);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) eventView.getLayoutParams();
float margin = (fromMinutes * 60);
float distance = (fromMinutes - toMinutes);
float height = (distance * 60);
int result = ((int)margin);
int result1 = ((int)height);
layoutParams.topMargin = dpToPixels(result+10);
layoutParams.height = dpToPixels(result1);
eventView.setLayoutParams(layoutParams);
dayplanView.addView(eventView);
}
Is this right??
