• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Populating Grid View

NanoUser

Lurker
Hei. I am new in android development.
and currently i am trying to populate my gridview to store an icon inside of it.
and each gridview is unique to the other gridview.
I have tried to populate the gridview using this code.

[HIGH]public void addRulePressed(View view){
LinearLayout layout = new LinearLayout(this);

layout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
50));
layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setBackgroundColor(Color.GRAY);

TextView number = new TextView(this);
number.setText((String.valueOf(ruleArrayAdapter.getCount()+1+".")));
number.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT));

conditionsList = new ArrayList<ImageView>();

conditionGV = new GridView(this);
conditionGV.setTag("ConditionPanel");
conditionGV.setLayoutParams(new LinearLayout.LayoutParams(0,LayoutParams.MATCH_PARENT,1f));
conditionGV.setBackgroundColor(Color.BLUE);
conditionGV.setOnDragListener(new MyDragListener());
conditionsAdapter = new GridViewAdapter(this,conditionsList);
conditionGV.setAdapter(conditionsAdapter);


actionsList = new ArrayList<ImageView>();
actionGV = new GridView(this);
actionGV.setTag("ActionPanel");
actionGV.setLayoutParams(new LinearLayout.LayoutParams(0,LayoutParams.MATCH_PARENT,1f));
actionGV.setBackgroundColor(Color.RED);
actionGV.setOnDragListener(new MyDragListener());
actionsAdapter = new GridViewAdapter(this,actionsList);
actionGV.setAdapter(actionsAdapter);

View line = new View(this);
line.setLayoutParams(new LinearLayout.LayoutParams(0,2,0.2f));
line.setBackgroundColor(Color.BLACK);

layout.addView(number);
layout.addView(conditionGV);
layout.addView(line);
layout.addView(actionGV);

ruleArrayAdapter.add(layout);
ruleArrayAdapter.notifyDataSetChanged();
ruleListView.invalidate();

}

[/HIGH]

when i press a button, it will populate the line of gridview
and i can drag every icon into each separate gridview.
icon will be stored in the conditionlist/actionlist array.
what i want to achieve:
1. [X=======] - [A=======]
2. [Y=======] - [B=======]
3. [Z=======] - [C=======]

[=====] => gridview; A,B,C,X,Y,Z => imageview

however, the problem i encounter are:
1. gridview will only show up in every 2 line of gridview being added
2. icon can only be dragged into the last line of gridview
can somebody help me about this?
 
Back
Top Bottom