Update ListView from OnItemClickListener of GridView from TabContenFactory class

Last Updated: 2013-06-11 09:07:05
  1. tempdatasave

    tempdatasave New Member

    I am new to android (with C# background) and trying to develop my first big application.

    I have a TableView at top and inside my table view I have a Tab view on left and a ListView on right. My Tab view contains Gridview which contains ImageView with Text belowImage.

    Now what I want to do is, first somehow I want to link each gridview item with a special code. So my quest is what is the best way to do this,
    1. Keep a two dimensional array or dictionary (if exist) to find code for each item of gridview
    2. Somehow Add this code with each item when adding items into girdview (this should not be display on the screen). e.g with some hidden property. Please suggest how.

    Second thing I want to do is, whenever user clicks on any item in gridview, name of the item and associated code should be added into the listview. The way I have done this by accessing listview in onItemClickListener event on grid as shown in code below.
    Is this the good way to do this or is there any other better way? Please suggest.

    Here java class of main activity
    protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.myactivity );

    List<String> items = new ArrayList<String>();
    ListView lv = (ListView) findViewById(R.id.listView1);
    lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items));

    TabHost tabHost = (TabHost)findViewById(R.id.mytabhost);
    for(int i=1;i<=3;i++)

    TabSpec spec = tabHost.newTabSpec("tag"+i);
    spec.setContent(new TabHost.TabContentFactory() {

    public View createTabContent(String arg0) {
    final String[] sa = new String[25];
    GridView gv = new GridView(MainActivity.this);
    gv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT) );
    Resources r = Resources.getSystem();
    int px =(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());
    px =(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, r.getDisplayMetrics());
    gv.setPadding(0, px, px, px);
    for(int j=0;j<25;j++)

    GridAdapter ga = new GridAdapter(MainActivity.this,25);


    gv.setOnItemClickListener(new OnItemClickListener(){

    public void onItemClick(AdapterView<?> parent, View arg1,
    int position, long arg3) {

    ArrayAdapter aad = (ArrayAdapter)((ListView)MainActivity.this.findViewById(R.id.listView1)).getAdapter();
    aad.add("New Ite");
    Toast.makeText(MainActivity.this, "Clicked GV " , Toast.LENGTH_SHORT).show();

    return gv;


  2. tempdatasave

    tempdatasave New Member

    Any suggestion?

Share This Page