I have a GridView
for students and think like I fill every cell with one student name, and in every GridCell
that student has name he also got all marks that he got for whole year in the same cell. So in every cell I have like:
a gridview
-------------------------------
| student 1 | student 2 |
| | |
| a listview | |
| or scrollview | a listview |
| ---------- | ----------- |
| english A | english B |
| math A | math A |
| history A | history E |
-----------------------------
and current xml for this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/senaryolar_grid"
android:layout_width="166dp"
android:layout_height="210dp"
android:padding="3dp"
android:background="@color/white">
<RelativeLayout
android:layout_width="166dp"
android:layout_height="32dp"
android:background="@drawable/senaryobaslik"
android:id="@+id/senaryo_baslik">
<TextView android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/senaryo_baslik_tv"
android:textColor="@color/white"
android:layout_marginLeft="4dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/senaryo_baslik_iv"
android:src="@drawable/arti"
android:layout_width="22dp"
android:layout_height="18dp"
android:layout_toRightOf="@id/senaryo_baslik_tv"/>
</RelativeLayout>
<ScrollView
android:layout_height="50dp"
android:layout_width="fill_parent"
android:id="@+id/senaryo_scrollview"
android:layout_below="@id/senaryo_baslik">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/senaryo_scroll_ll">
</LinearLayout>
</ScrollView>
</RelativeLayout>
so my problem is I try to generate these listviews
or scrollview
(tried both) inside my getView()
function of my gridview
since I didnt know that getView()
function called a looot of times while gridview
is generated by getview()
function so I tried to put my generater inside a getView()
function but it didnt work and I got outofmemoryexception
, and my question is: "Where should I call my listview adapter
?" to create it dynamicly inside my gridview
according to students id if I can not call it in getview()
?
My current gridviewadapter
:
(I just put this gridviewadapter
's getview()
function and the xml code above to show you what I try to do, but be aware that this is not the correct way to do what I am trying to do)
public View getView(int position, View grid, ViewGroup parent) {
if(grid == null){
grid=layoutInflator.inflate(R.layout.senaryolar_grid, null);
}
ArrayList<ControlItem> senario_devices = new ArrayList<ControlItem>();
// here think like senario_id is student_id
int senario_id = samples_senario.get(position).getSenarioId();
// here think like getSenarioDevices is getStudentMarks
senario_devices = dbhelpit.getSenarioDevices(senario_id);
int senario_device_size = senario_devices.size();
TextView tv_senario;
ImageView iv_senario;
// I tried scrollview too since I thought listview adapters created outof memory exception but off course didnt work since its not the main problem
ScrollView lv_senario;
tv_senario = (TextView) grid.findViewById(R.id.senaryo_baslik_tv);
iv_senario = (ImageView) grid.findViewById(R.id.senaryo_baslik_iv);
lv_senario = (ScrollView) grid.findViewById(R.id.senaryo_scrollview);
tv_senario.setText(samples_senario.get(position).getSenarioName());
int i = 0;
LinearLayout ll = (LinearLayout) grid.findViewById(R.id.senaryo_scroll_ll);
while(i < senario_device_size){
View temp = layoutInflator.inflate(R.layout.senaryolar_listview, null);
TextView tv;
ImageView iv;
RelativeLayout rl;
iv = (ImageView) temp.findViewById(R.id.senaryo_list_baslik_iv);
rl = (RelativeLayout) temp.findViewById(R.id.senaryolar_list);
tv = (TextView) temp.findViewById(R.id.senaryo_list_text_tv);
tv.setText(senario_devices.get(position).getDeviceName());
ll.addView(rl);
i++;
}
return grid;
}
So if you had a grid view adapter and you want to create a listViewAdapter
in every grid cell where whould you call those listViewAdapters
while you can't call in getView()
function, it doesn't have to be a listview
, it can be only a pure while that echoes the results like an array
, I hope the question is clear. Thank you!